ew_base/Classes/ViewHelpers/PublicPathViewHelper.php
2024-12-14 14:03:20 +01:00

68 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Evoweb\EwBase\ViewHelpers;
/*
* This file is developed by evoWeb.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* = Examples =
*
* <code title="Simple Loop">
* <ewb:publicPath path="{data}">....</ewb:publicPath>
* </code>
* <output>
* fixed flexform data for extbase controller
* </output>
*
* @api
*/
class PublicPathViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* @var boolean
*/
protected $escapeOutput = false;
protected static ?array $frontendGroupIds = null;
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('path', 'string', 'Extension resource path', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return bool
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$path = (string)$arguments['path'];
return PathUtility::getPublicResourceWebPath($path);
}
}