‪TYPO3CMS  11.5
HtmlentitiesViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
20 
51 {
52  use CompileWithContentArgumentAndRenderStatic;
53 
59  protected ‪$escapeOutput = false;
60 
66  protected ‪$escapeChildren = false;
67 
71  public function ‪initializeArguments()
72  {
73  $this->registerArgument('value', 'string', 'string to format');
74  $this->registerArgument('keepQuotes', 'bool', 'If TRUE, single and double quotes won\'t be replaced (sets ENT_NOQUOTES flag).', false, false);
75  $this->registerArgument('encoding', 'string', 'Define the encoding used when converting characters (Default: UTF-8');
76  $this->registerArgument('doubleEncode', 'bool', 'If FALSE existing html entities won\'t be encoded, the default is to convert everything.', false, true);
77  }
78 
88  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
89  {
90  $value = $renderChildrenClosure();
91  $encoding = $arguments['encoding'];
92  $keepQuotes = $arguments['keepQuotes'];
93  $doubleEncode = $arguments['doubleEncode'];
94 
95  if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) {
96  return $value;
97  }
98  if ($encoding === null) {
99  $encoding = ‪self::resolveDefaultEncoding();
100  }
101  $flags = $keepQuotes ? ENT_NOQUOTES : ENT_QUOTES;
102  return htmlentities((string)$value, $flags, $encoding, $doubleEncode);
103  }
104 }
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: HtmlentitiesViewHelper.php:85
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: HtmlentitiesViewHelper.php:57
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: HtmlentitiesViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Format\AbstractEncodingViewHelper
Definition: AbstractEncodingViewHelper.php:25
‪TYPO3\CMS\Fluid\ViewHelpers\Format\AbstractEncodingViewHelper\resolveDefaultEncoding
‪static string resolveDefaultEncoding()
Definition: AbstractEncodingViewHelper.php:35
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper
Definition: HtmlentitiesViewHelper.php:51
‪TYPO3\CMS\Fluid\ViewHelpers\Format
Definition: AbstractEncodingViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper\initializeArguments
‪initializeArguments()
Definition: HtmlentitiesViewHelper.php:68