‪TYPO3CMS  10.4
SvgSpriteIconProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
31 {
38  protected function ‪generateMarkup(‪Icon $icon, array $options): string
39  {
40  if (empty($options['sprite'])) {
41  throw new \InvalidArgumentException('[' . $icon->‪getIdentifier() . '] The option "source" is required and must not be empty', 1603439142);
42  }
43 
44  $source = $options['sprite'];
45 
46  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
47  $source = GeneralUtility::getFileAbsFileName($source);
48  }
49 
50  $source = ‪PathUtility::getAbsoluteWebPath($source);
51  return '<svg class="icon-color" role="img"><use xlink:href="' . htmlspecialchars($source) . '" /></svg>';
52  }
53 
59  protected function ‪generateInlineMarkup(array $options): string
60  {
61  if (empty($options['source'])) {
62  throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1603439146);
63  }
64 
65  $source = $options['source'];
66 
67  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
68  $source = GeneralUtility::getFileAbsFileName($source);
69  }
70 
71  return $this->‪getInlineSvg($source);
72  }
73 }
‪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\Icon\getIdentifier
‪string getIdentifier()
Definition: Icon.php:135
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:22
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider
Definition: SvgSpriteIconProvider.php:31
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider\generateInlineMarkup
‪string generateInlineMarkup(array $options)
Definition: SvgSpriteIconProvider.php:59
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider\generateMarkup
‪string generateMarkup(Icon $icon, array $options)
Definition: SvgSpriteIconProvider.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43