Implement and apply icon viewhelper
This commit is contained in:
@@ -4,49 +4,33 @@ namespace EP\EpTheme\ViewHelpers;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
class IconViewHelper extends AbstractViewHelper
|
||||
class IconViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @var string
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
protected $tagName = 'svg';
|
||||
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
|
||||
$this->registerArgument('icon', 'string', 'Icon name');
|
||||
$this->registerArgument('class', 'string', 'CSS classes');
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerArgument('icon', 'string', 'Icon name', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderStatic(
|
||||
array $arguments,
|
||||
\Closure $renderChildrenClosure,
|
||||
RenderingContextInterface $renderingContext
|
||||
)
|
||||
public function render(): string
|
||||
{
|
||||
$imageService = self::getImageService();
|
||||
$sprite = $imageService->getImage('EXT:ep_theme/Resources/Public/images/icons_sprite.svg', null, false);
|
||||
$imageUrl = $sprite->getPublicUrl();
|
||||
|
||||
return sprintf(
|
||||
'<svg class="%s"><use href="%s#icon-%s"></use></svg>',
|
||||
$arguments['class'],
|
||||
$imageUrl,
|
||||
$arguments['icon']
|
||||
);
|
||||
$content = sprintf('<use href="%s#icon-%s"></use>', $imageUrl, $this->arguments['icon']);
|
||||
$this->tag->setContent($content);
|
||||
|
||||
return $this->tag->render();
|
||||
}
|
||||
|
||||
protected static function getImageService()
|
||||
|
||||
Reference in New Issue
Block a user