‪TYPO3CMS  9.5
JsonViewHelper.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 originated from the Neos.Form package (www.neos.io)
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
22 
58 class ‪JsonViewHelper extends AbstractViewHelper
59 {
60  use CompileWithContentArgumentAndRenderStatic;
61 
65  protected ‪$escapeChildren = false;
66 
70  public function ‪initializeArguments()
71  {
72  $this->registerArgument('value', 'mixed', 'The incoming data to convert, or null if VH children should be used');
73  $this->registerArgument('forceObject', 'bool', 'Outputs an JSON object rather than an array', false, false);
74  }
75 
91  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
92  {
93  $value = $renderChildrenClosure();
94  $options = JSON_HEX_TAG;
95  if ($arguments['forceObject'] !== false) {
96  $options = $options | JSON_FORCE_OBJECT;
97  }
98  return json_encode($value, $options);
99  }
100 }
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: JsonViewHelper.php:89
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\initializeArguments
‪initializeArguments()
Definition: JsonViewHelper.php:68
‪TYPO3\CMS\Fluid\ViewHelpers\Format
Definition: AbstractEncodingViewHelper.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: JsonViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper
Definition: JsonViewHelper.php:59