‪TYPO3CMS  10.4
FormViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 /*
19  * Inspired by and partially taken from the Neos.Form package (www.neos.io)
20  */
21 
23 
25 use ‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper as FluidFormViewHelper;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
28 
34 class ‪FormViewHelper extends FluidFormViewHelper
35 {
36 
43  protected function ‪renderHiddenReferrerFields()
44  {
45  $formRuntime = $this->‪getFormRuntime();
46  $prefix = $this->‪prefixFieldName($this->‪getFormObjectName());
47 
48  $markup = $this->‪createHiddenInputElement(
49  $prefix . '[__state]',
50  $this->hashService->appendHmac(
51  base64_encode(serialize($formRuntime->getFormState()))
52  )
53  );
54 
55  // ONLY assign `__session` if form is performing (uncached)
56  if ($formRuntime->canProcessFormSubmission() && $formRuntime->getFormSession() !== null) {
57  $markup .= $this->‪createHiddenInputElement(
58  $prefix . '[__session]',
59  $formRuntime->getFormSession()->getAuthenticatedIdentifier()
60  );
61  }
62  return $markup;
63  }
64 
70  protected function ‪createHiddenInputElement(string $name, string $value): string
71  {
72  $tagBuilder = GeneralUtility::makeInstance(TagBuilder::class, 'input');
73  $tagBuilder->addAttribute('type', 'hidden');
74  $tagBuilder->addAttribute('name', $name);
75  $tagBuilder->addAttribute('value', $value);
76  return $tagBuilder->render();
77  }
78 
85  protected function ‪getFormObjectName()
86  {
87  return $this->‪getFormRuntime()->getFormDefinition()->getIdentifier();
88  }
89 
90  protected function ‪getFormRuntime(): ‪FormRuntime
91  {
92  return $this->arguments['object'];
93  }
94 }
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:103
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\renderHiddenReferrerFields
‪string renderHiddenReferrerFields()
Definition: FormViewHelper.php:43
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\getFormObjectName
‪string getFormObjectName()
Definition: FormViewHelper.php:85
‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:61
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\getFormRuntime
‪getFormRuntime()
Definition: FormViewHelper.php:90
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\prefixFieldName
‪string prefixFieldName($fieldName)
Definition: AbstractFormViewHelper.php:50
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\createHiddenInputElement
‪string createHiddenInputElement(string $name, string $value)
Definition: FormViewHelper.php:70
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:35