[BUGFIX] Supply returnURL to EXT:beuser usergroups
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / ArrayElementViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\ViewHelpers;
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 TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20
21 /**
22 * Get a value from an array by given key.
23 */
24 class ArrayElementViewHelper extends AbstractViewHelper implements CompilableInterface
25 {
26 /**
27 * Return array element by key. Accessed values must be scalar (string, int, float or double)
28 *
29 * @param array $array Array to search in
30 * @param string $key Key to return its value
31 * @param string $subKey If result of key access is an array, subkey can be used to fetch an element from this again
32 * @return string
33 */
34 public function render(array $array, $key, $subKey = '')
35 {
36 return static::renderStatic(
37 array(
38 'array' => $array,
39 'key' => $key,
40 'subKey' => $subKey
41 ),
42 $this->buildRenderChildrenClosure(),
43 $this->renderingContext
44 );
45 }
46
47 /**
48 * Return array element by key.
49 *
50 * @param array $arguments
51 * @param \Closure $renderChildrenClosure
52 * @param RenderingContextInterface $renderingContext
53 * @throws \TYPO3\CMS\Beuser\Exception
54 * @return string
55 */
56 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
57 {
58 $array = $arguments['array'];
59 $key = $arguments['key'];
60 $subKey = $arguments['subKey'];
61 $result = '';
62 if (is_array($array) && isset($array[$key])) {
63 $result = $array[$key];
64 if (is_array($result) && $subKey && isset($result[$subKey])) {
65 $result = $result[$subKey];
66 }
67 }
68 if (!is_scalar($result)) {
69 throw new \TYPO3\CMS\Beuser\Exception(
70 'Only scalar return values (string, int, float or double) are supported.',
71 1382284105
72 );
73 }
74 return $result;
75 }
76 }