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