‪TYPO3CMS  ‪main
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;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
29 
35 final class ‪FormViewHelper extends FluidFormViewHelper
36 {
43  protected function ‪renderHiddenReferrerFields(): string
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  HashScope::FormState->prefix()
53  )
54  );
55 
56  // ONLY assign `__session` if form is performing (uncached)
57  if ($formRuntime->canProcessFormSubmission() && $formRuntime->getFormSession() !== null) {
58  $markup .= $this->‪createHiddenInputElement(
59  $prefix . '[__session]',
60  $formRuntime->getFormSession()->getAuthenticatedIdentifier()
61  );
62  }
63  return $markup;
64  }
65 
66  protected function ‪createHiddenInputElement(string $name, string $value): string
67  {
68  $tagBuilder = GeneralUtility::makeInstance(TagBuilder::class, 'input');
69  $tagBuilder->addAttribute('type', 'hidden');
70  $tagBuilder->addAttribute('name', $name);
71  $tagBuilder->addAttribute('value', $value);
72  return $tagBuilder->render();
73  }
74 
79  protected function ‪getFormObjectName(): string
80  {
81  return $this->‪getFormRuntime()->getFormDefinition()->getIdentifier();
82  }
83 
84  protected function ‪getFormRuntime(): ‪FormRuntime
85  {
86  return $this->arguments['object'];
87  }
88 }
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:106
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\renderHiddenReferrerFields
‪string renderHiddenReferrerFields()
Definition: FormViewHelper.php:43
‪TYPO3\CMS\Form\Security\HashScope
‪HashScope
Definition: HashScope.php:25
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\createHiddenInputElement
‪createHiddenInputElement(string $name, string $value)
Definition: FormViewHelper.php:66
‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:72
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\getFormRuntime
‪getFormRuntime()
Definition: FormViewHelper.php:84
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\prefixFieldName
‪prefixFieldName(string $fieldName)
Definition: AbstractFormViewHelper.php:46
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper\getFormObjectName
‪getFormObjectName()
Definition: FormViewHelper.php:79
‪TYPO3\CMS\Form\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:36