‪TYPO3CMS  10.4
SvgIconProvider.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 {
34  protected function ‪generateMarkup(‪Icon $icon, array $options): string
35  {
36  if (empty($options['source'])) {
37  throw new \InvalidArgumentException('[' . $icon->‪getIdentifier() . '] The option "source" is required and must not be empty', 1460976566);
38  }
39 
40  $source = $options['source'];
41 
42  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
43  $source = GeneralUtility::getFileAbsFileName($source);
44  }
45 
46  $source = ‪PathUtility::getAbsoluteWebPath($source);
47  return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->‪getDimension()->‪getWidth() . '" height="' . $icon->‪getDimension()->‪getHeight() . '" alt="" />';
48  }
49 
55  protected function ‪generateInlineMarkup(array $options): string
56  {
57  if (empty($options['source'])) {
58  throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1460976610);
59  }
60 
61  $source = $options['source'];
62 
63  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
64  $source = GeneralUtility::getFileAbsFileName($source);
65  }
66 
67  return $this->‪getInlineSvg($source);
68  }
69 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getInlineSvg
‪getInlineSvg(string $source)
Definition: AbstractSvgIconProvider.php:44
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider
Definition: AbstractSvgIconProvider.php:28
‪TYPO3\CMS\Core\Imaging\IconProvider
Definition: AbstractSvgIconProvider.php:18
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider\generateMarkup
‪string generateMarkup(Icon $icon, array $options)
Definition: SvgIconProvider.php:34
‪TYPO3\CMS\Core\Imaging\Dimension\getHeight
‪int getHeight()
Definition: Dimension.php:72
‪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\SvgIconProvider\generateInlineMarkup
‪string generateInlineMarkup(array $options)
Definition: SvgIconProvider.php:55
‪TYPO3\CMS\Core\Imaging\Dimension\getWidth
‪int getWidth()
Definition: Dimension.php:63
‪TYPO3\CMS\Core\Imaging\Icon\getDimension
‪Dimension getDimension()
Definition: Icon.php:220
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
Definition: SvgIconProvider.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43