‪TYPO3CMS  ‪main
BitmapIconProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
28  public const ‪MARKUP_IDENTIFIER_INLINE = 'inline';
29 
30  public function ‪prepareIconMarkup(‪Icon $icon, array $options = [])
31  {
32  $icon->‪setMarkup($this->‪generateMarkup($icon, $options));
33  $icon->‪setAlternativeMarkup(self::MARKUP_IDENTIFIER_INLINE, $this->‪generateInlineMarkup($icon, $options));
34  }
35 
40  protected function ‪generateMarkup(‪Icon $icon, array $options)
41  {
42  if (empty($options['source'])) {
43  throw new \InvalidArgumentException('[' . $icon->‪getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
44  }
45 
46  $source = $options['source'];
47 
48  return '<img src="' . htmlspecialchars($this->‪getPublicPath($source)) . '" width="' . $icon->‪getDimension()->getWidth() . '" height="' . $icon->‪getDimension()->getHeight() . '" alt="" />';
49  }
50 
54  protected function ‪getPublicPath(string $source): string
55  {
56  if (‪PathUtility::isExtensionPath($source)) {
58  }
59  // TODO: deprecate non extension resources in icon API
60  return ‪PathUtility::getAbsoluteWebPath(‪PathUtility::isAbsolutePath($source) ? $source : GeneralUtility::getFileAbsFileName($source));
61  }
62 
67  protected function ‪generateInlineMarkup(‪Icon $icon, array $options)
68  {
69  if (empty($options['source'])) {
70  throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1471460676);
71  }
72 
73  $source = $options['source'];
74 
75  $filePath = ‪PathUtility::isAbsolutePath($source) ? $source : GeneralUtility::getFileAbsFileName($source);
76 
77  if (!file_exists($filePath)) {
78  return '';
79  }
80 
81  return sprintf(
82  '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %1$d %2$d" width="%1$d" height="%2$d"><image width="%1$d" height="%1$d" xlink:href="%3$s"/></svg>',
83  $icon->‪getDimension()->getWidth(),
84  $icon->‪getDimension()->getHeight(),
85  $this->getPublicPath($source)
86  );
87  }
88 }
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:118
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Imaging\Icon\setAlternativeMarkup
‪$this setAlternativeMarkup(string $markupIdentifier, string $markup)
Definition: Icon.php:135
‪TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath
‪static isAbsolutePath(string $path)
Definition: PathUtility.php:287
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\getPublicPath
‪getPublicPath(string $source)
Definition: BitmapIconProvider.php:54
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Imaging\IconProvider
Definition: AbstractSvgIconProvider.php:18
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\prepareIconMarkup
‪prepareIconMarkup(Icon $icon, array $options=[])
Definition: BitmapIconProvider.php:30
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider
Definition: BitmapIconProvider.php:27
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:22
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath(string $targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:52
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: BitmapIconProvider.php:28
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:98
‪TYPO3\CMS\Core\Imaging\Icon\getIdentifier
‪getIdentifier()
Definition: Icon.php:141
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateMarkup
‪string generateMarkup(Icon $icon, array $options)
Definition: BitmapIconProvider.php:40
‪TYPO3\CMS\Core\Imaging\Icon\getDimension
‪getDimension()
Definition: Icon.php:232
‪TYPO3\CMS\Core\Imaging\Icon\setMarkup
‪$this setMarkup(string $markup)
Definition: Icon.php:121
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateInlineMarkup
‪string generateInlineMarkup(Icon $icon, array $options)
Definition: BitmapIconProvider.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52