‪TYPO3CMS  10.4
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  const ‪MARKUP_IDENTIFIER_INLINE = 'inline';
29 
34  public function ‪prepareIconMarkup(‪Icon $icon, array $options = [])
35  {
36  $icon->‪setMarkup($this->‪generateMarkup($icon, $options));
37  $icon->‪setAlternativeMarkup(self::MARKUP_IDENTIFIER_INLINE, $this->‪generateInlineMarkup($icon, $options));
38  }
39 
46  protected function ‪generateMarkup(‪Icon $icon, array $options)
47  {
48  if (empty($options['source'])) {
49  throw new \InvalidArgumentException('[' . $icon->‪getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
50  }
51 
52  $source = $options['source'];
53 
54  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
55  $source = GeneralUtility::getFileAbsFileName($source);
56  }
57  $source = ‪PathUtility::getAbsoluteWebPath($source);
58 
59  return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->‪getDimension()->‪getWidth() . '" height="' . $icon->‪getDimension()->‪getHeight() . '" alt="" />';
60  }
61 
68  protected function ‪generateInlineMarkup(‪Icon $icon, array $options)
69  {
70  if (empty($options['source'])) {
71  throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1471460676);
72  }
73 
74  $source = $options['source'];
75 
76  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
77  $source = GeneralUtility::getFileAbsFileName($source);
78  }
79 
80  if (!file_exists($source)) {
81  return '';
82  }
83 
84  return sprintf(
85  '<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>',
86  $icon->‪getDimension()->‪getWidth(),
87  $icon->‪getDimension()->‪getHeight(),
89  );
90  }
91 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\IconProvider
Definition: AbstractSvgIconProvider.php:18
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\prepareIconMarkup
‪prepareIconMarkup(Icon $icon, array $options=[])
Definition: BitmapIconProvider.php:34
‪TYPO3\CMS\Core\Imaging\Dimension\getHeight
‪int getHeight()
Definition: Dimension.php:72
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider
Definition: BitmapIconProvider.php:27
‪TYPO3\CMS\Core\Imaging\Icon\getIdentifier
‪string getIdentifier()
Definition: Icon.php:135
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:22
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: BitmapIconProvider.php:28
‪TYPO3\CMS\Core\Imaging\Icon\setMarkup
‪setMarkup($markup)
Definition: Icon.php:108
‪TYPO3\CMS\Core\Imaging\Dimension\getWidth
‪int getWidth()
Definition: Dimension.php:63
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateMarkup
‪string generateMarkup(Icon $icon, array $options)
Definition: BitmapIconProvider.php:46
‪TYPO3\CMS\Core\Imaging\Icon\getDimension
‪Dimension getDimension()
Definition: Icon.php:220
‪TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateInlineMarkup
‪string generateInlineMarkup(Icon $icon, array $options)
Definition: BitmapIconProvider.php:68
‪TYPO3\CMS\Core\Imaging\Icon\setAlternativeMarkup
‪setAlternativeMarkup($markupIdentifier, $markup)
Definition: Icon.php:127
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43