* Home * * ``` * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-transform-html */ final class HtmlViewHelper extends AbstractViewHelper { protected const array MAP_ON_FAILURE = [ '' => 0, 'null' => 0, 'removeTag' => HtmlWorker::REMOVE_TAG_ON_FAILURE, 'removeAttr' => HtmlWorker::REMOVE_ATTR_ON_FAILURE, 'removeEnclosure' => HtmlWorker::REMOVE_ENCLOSURE_ON_FAILURE, ]; /** * @var bool */ protected $escapeChildren = false; /** * @var bool */ protected $escapeOutput = false; public function __construct( private readonly HtmlWorker $htmlWorker ) {} public function initializeArguments(): void { $this->registerArgument('selector', 'string', 'comma separated list of node attributes to be considered', false, 'a.href'); $this->registerArgument('onFailure', 'string', 'behavior on failure, either `removeTag`, `removeAttr`, `removeEnclosure` or `null`', false, 'removeEnclosure'); } /** * @return string transformed markup */ public function render(): string { $content = $this->renderChildren(); $selector = $this->arguments['selector']; $onFailure = $this->arguments['onFailure']; $onFailureFlags = self::MAP_ON_FAILURE[$onFailure] ?? HtmlWorker::REMOVE_ENCLOSURE_ON_FAILURE; return (string)$this->htmlWorker ->parse((string)$content) ->transformUri($selector, $onFailureFlags); } }