‪TYPO3CMS  10.4
AbstractFormViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
23 
30 abstract class ‪AbstractFormViewHelper extends AbstractTagBasedViewHelper
31 {
35  protected ‪$persistenceManager;
36 
41  {
42  $this->persistenceManager = ‪$persistenceManager;
43  }
44 
51  protected function ‪prefixFieldName($fieldName)
52  {
53  if ($fieldName === null || $fieldName === '') {
54  return '';
55  }
56  $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
57  if (!$viewHelperVariableContainer->exists(FormViewHelper::class, 'fieldNamePrefix')) {
58  return $fieldName;
59  }
60  $fieldNamePrefix = (string)$viewHelperVariableContainer->get(FormViewHelper::class, 'fieldNamePrefix');
61  if ($fieldNamePrefix === '') {
62  return $fieldName;
63  }
64  $fieldNameSegments = explode('[', $fieldName, 2);
65  $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']';
66  if (count($fieldNameSegments) > 1) {
67  $fieldName .= '[' . $fieldNameSegments[1];
68  }
69  return $fieldName;
70  }
71 
80  protected function ‪renderHiddenIdentityField($object, $name)
81  {
82  if ($object instanceof ‪LazyLoadingProxy) {
83  $object = $object->_loadRealInstance();
84  }
85  if (!is_object($object)
86  || !($object instanceof ‪AbstractDomainObject)
87  || ($object->_isNew() && !$object->_isClone())) {
88  return '';
89  }
90  // Intentionally NOT using PersistenceManager::getIdentifierByObject here!!
91  // Using that one breaks re-submission of data in forms in case of an error.
92  $identifier = $object->getUid();
93  if ($identifier === null) {
94  return LF . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . LF;
95  }
96  $name = $this->‪prefixFieldName($name) . '[__identity]';
98 
99  return LF . '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($identifier) . '" />' . LF;
100  }
101 
107  protected function ‪registerFieldNameForFormTokenGeneration($fieldName)
108  {
109  $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
110  if ($viewHelperVariableContainer->exists(FormViewHelper::class, 'formFieldNames')) {
111  $formFieldNames = $viewHelperVariableContainer->get(FormViewHelper::class, 'formFieldNames');
112  } else {
113  $formFieldNames = [];
114  }
115  $formFieldNames[] = $fieldName;
116  $viewHelperVariableContainer->addOrUpdate(FormViewHelper::class, 'formFieldNames', $formFieldNames);
117  }
118 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\injectPersistenceManager
‪injectPersistenceManager(PersistenceManagerInterface $persistenceManager)
Definition: AbstractFormViewHelper.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\$persistenceManager
‪TYPO3 CMS Extbase Persistence PersistenceManagerInterface $persistenceManager
Definition: AbstractFormViewHelper.php:34
‪TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
Definition: PersistenceManagerInterface.php:22
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\renderHiddenIdentityField
‪string renderHiddenIdentityField($object, $name)
Definition: AbstractFormViewHelper.php:79
‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:61
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\registerFieldNameForFormTokenGeneration
‪registerFieldNameForFormTokenGeneration($fieldName)
Definition: AbstractFormViewHelper.php:106
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject
Definition: AbstractDomainObject.php:31
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
Definition: AbstractFormViewHelper.php:31
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:29
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\prefixFieldName
‪string prefixFieldName($fieldName)
Definition: AbstractFormViewHelper.php:50