‪TYPO3CMS  11.5
JsonViewHelper.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 
16 /*
17  * Inspired by and partially taken from the Neos.Form package (www.neos.io)
18  */
19 
21 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
25 
61 class ‪JsonViewHelper extends AbstractViewHelper
62 {
63  use CompileWithContentArgumentAndRenderStatic;
64 
68  protected ‪$escapeChildren = false;
69 
73  public function ‪initializeArguments()
74  {
75  $this->registerArgument('value', 'mixed', 'The incoming data to convert, or null if VH children should be used');
76  $this->registerArgument('forceObject', 'bool', 'Outputs an JSON object rather than an array', false, false);
77  }
78 
94  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
95  {
96  $value = $renderChildrenClosure();
97  $options = JSON_HEX_TAG;
98  if ($arguments['forceObject'] !== false) {
99  $options = $options | JSON_FORCE_OBJECT;
100  }
101  return json_encode($value, $options);
102  }
103 }
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: JsonViewHelper.php:92
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\initializeArguments
‪initializeArguments()
Definition: JsonViewHelper.php:71
‪TYPO3\CMS\Fluid\ViewHelpers\Format
Definition: AbstractEncodingViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: JsonViewHelper.php:66
‪TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper
Definition: JsonViewHelper.php:62