ew_base/Classes/ViewHelpers/PublicPathViewHelper.php
2024-05-25 16:24:24 +02:00

64 lines
1.6 KiB
PHP
Executable File

<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Evoweb\EwBase\ViewHelpers;
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 bool
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('path', 'string', 'Extension resource path', true);
}
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
$path = (string)$arguments['path'];
try {
$path = PathUtility::getPublicResourceWebPath($path);
} catch (\Exception) {
$path = '';
}
return $path;
}
}