[TASK] Adjust contrast colors in diff view
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ViewHelpers / Format / ImplodeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ViewHelpers\Format;
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\ViewHelper\AbstractViewHelper;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20
21 /**
22 * A view helper which joins array elements with a glue string.
23 *
24 * = Examples =
25 *
26 * <code>
27 * class="<f:format.implode values="{0: 'className-1', 1: 'className-2'}" />"
28 * </code>
29 *
30 * <output>
31 * class="className-1 className-2"
32 * </output>
33 *
34 * <code>
35 * class="{f:format.implode(values:'{0:\'className-1\', 1:\'className-2\'}')}"
36 * </code>
37 *
38 * <output>
39 * class="className-1 className-2"
40 * </output>
41 *
42 * <code>
43 * class="<f:format.implode values="{0: 'prefix', 1: 'value1', 2: 'value2'}" glue="-" />"
44 * </code>
45 *
46 * <output>
47 * class="prefix-value1-value2"
48 * </output>
49 */
50 class ImplodeViewHelper extends AbstractViewHelper implements CompilableInterface {
51
52 /**
53 * Render the view helper
54 *
55 * @param array $values array of elements to join
56 * @param string $glue String used as glue between elements
57 * @param bool $excludeEmptyValues Remove empty elements from $values
58 * @return string
59 */
60 public function render(array $values, $glue = ', ', $excludeEmptyValues = TRUE) {
61 return self::renderStatic(
62 array(
63 'values' => $values,
64 'glue' => $glue,
65 'excludeEmptyValues' => $excludeEmptyValues
66 ),
67 $this->buildRenderChildrenClosure(),
68 $this->renderingContext
69 );
70 }
71
72 /**
73 * @param array $arguments
74 * @param \Closure $renderChildrenClosure
75 * @param RenderingContextInterface $renderingContext
76 * @return string
77 */
78 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
79 $values = (array)$arguments['values'];
80 if (empty($values)) {
81 $values =(array)$renderChildrenClosure();
82 }
83 $glue = $arguments['glue'];
84 $excludeEmptyValues = (bool)$arguments['excludeEmptyValues'];
85 $string = '';
86
87 if ($excludeEmptyValues) {
88 $values = array_filter($values);
89 }
90 if (!empty($values)) {
91 $string = implode($glue, $values);
92 }
93 return $string;
94 }
95 }