‪TYPO3CMS  9.5
HtmlViewHelper.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 
22 use TYPO3\HtmlSanitizer\Builder\BuilderInterface;
23 use TYPO3\HtmlSanitizer\Sanitizer;
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
28 
58 class ‪HtmlViewHelper extends AbstractViewHelper
59 {
60  use CompileWithRenderStatic;
61 
65  protected ‪$escapeChildren = false;
66 
70  protected ‪$escapeOutput = false;
71 
75  public function ‪initializeArguments()
76  {
77  $this->registerArgument(
78  'build',
79  'string',
80  'preset name or class-like name of sanitization builder',
81  false,
82  'default'
83  );
84  }
85 
93  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
94  {
95  $value = $renderChildrenClosure();
96  $build = $arguments['build'] ?? 'default';
97  return static::createSanitizer($build)->sanitize($value);
98  }
99 
100  protected static function ‪createSanitizer(string $build): Sanitizer
101  {
102  if (class_exists($build) && is_a($build, BuilderInterface::class, true)) {
103  $builder = GeneralUtility::makeInstance($build);
104  } else {
105  $factory = GeneralUtility::makeInstance(SanitizerBuilderFactory::class);
106  $builder = $factory->build($build);
107  }
108  return $builder->build();
109  }
110 }
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: HtmlViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: HtmlViewHelper.php:90
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper
Definition: HtmlViewHelper.php:59
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\createSanitizer
‪static createSanitizer(string $build)
Definition: HtmlViewHelper.php:97
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\initializeArguments
‪initializeArguments()
Definition: HtmlViewHelper.php:72
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize
Definition: HtmlViewHelper.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: HtmlViewHelper.php:67
‪TYPO3\CMS\Core\Html\SanitizerBuilderFactory
Definition: SanitizerBuilderFactory.php:35