TYPO3 CMS  TYPO3_7-6
AbstractFormViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
21 {
26 
30  public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
31  {
32  $this->persistenceManager = $persistenceManager;
33  }
34 
41  protected function prefixFieldName($fieldName)
42  {
43  if ($fieldName === null || $fieldName === '') {
44  return '';
45  }
46  if (!$this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')) {
47  return $fieldName;
48  }
49  $fieldNamePrefix = (string)$this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix');
50  if ($fieldNamePrefix === '') {
51  return $fieldName;
52  }
53  $fieldNameSegments = explode('[', $fieldName, 2);
54  $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']';
55  if (count($fieldNameSegments) > 1) {
56  $fieldName .= '[' . $fieldNameSegments[1];
57  }
58  return $fieldName;
59  }
60 
69  protected function renderHiddenIdentityField($object, $name)
70  {
71  if ($object instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
72  $object = $object->_loadRealInstance();
73  }
74  if (!is_object($object)
75  || !($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject)
76  || ($object->_isNew() && !$object->_isClone())) {
77  return '';
78  }
79  // Intentionally NOT using PersistenceManager::getIdentifierByObject here!!
80  // Using that one breaks re-submission of data in forms in case of an error.
81  $identifier = $object->getUid();
82  if ($identifier === null) {
83  return LF . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . LF;
84  }
85  $name = $this->prefixFieldName($name) . '[__identity]';
87 
88  return LF . '<input type="hidden" name="' . $name . '" value="' . $identifier . '" />' . LF;
89  }
90 
97  protected function registerFieldNameForFormTokenGeneration($fieldName)
98  {
99  if ($this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formFieldNames')) {
100  $formFieldNames = $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formFieldNames');
101  } else {
102  $formFieldNames = [];
103  }
104  $formFieldNames[] = $fieldName;
105  $this->viewHelperVariableContainer->addOrUpdate(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formFieldNames', $formFieldNames);
106  }
107 }
injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)