[FEATURE] EXT:form - integrate new form framework
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / ViewHelpers / PlainTextMailViewHelper.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\ViewHelpers;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
21
22 /**
23 * A viewhelper for the plain mail view
24 *
25 * Scope: frontend
26 * @api
27 */
28 class PlainTextMailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
29 {
30 use CompileWithRenderStatic;
31
32 /**
33 * Initialize the arguments.
34 *
35 * @return void
36 * @internal
37 */
38 public function initializeArguments()
39 {
40 parent::initializeArguments();
41 $this->registerArgument('formValue', 'array', 'The values from a form element', true);
42 $this->registerArgument('formRuntime', FormRuntime::class, 'A FormRuntime instance', true);
43 }
44
45 /**
46 * @param array $arguments
47 * @param callable|\Closure $renderChildrenClosure
48 * @param RenderingContextInterface $renderingContext
49 * @return string
50 * @api
51 */
52 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
53 {
54 $formValue = $arguments['formValue'];
55 $formRuntime = $arguments['formRuntime'];
56
57 $label = $formValue['element']->getLabel();
58 $label = TranslateElementPropertyViewHelper::renderStatic(
59 ['element' => $formValue['element'], 'property' => 'label', 'formRuntime' => $formRuntime],
60 $renderChildrenClosure,
61 $renderingContext
62 );
63 $processedValue = (!empty($formValue['processedValue'])) ? $formValue['processedValue'] : '-';
64 $isMultiValue = $formValue['isMultiValue'];
65
66 $label .= ': ';
67 if ($isMultiValue) {
68 $output = $label . array_shift($processedValue) . LF;
69 $indent = str_repeat(chr(32), (strlen($label)));
70 foreach ($processedValue as $multiValue) {
71 $output .= $indent . $multiValue;
72 }
73 } else {
74 $output = $label . $processedValue;
75 }
76
77 return $output . LF . LF;
78 }
79 }