TYPO3 CMS  TYPO3_6-2
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 
27 
34  protected function prefixFieldName($fieldName) {
35  if ($fieldName === NULL || $fieldName === '') {
36  return '';
37  }
38  if (!$this->viewHelperVariableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')) {
39  return $fieldName;
40  }
41  $fieldNamePrefix = (string) $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix');
42  if ($fieldNamePrefix === '') {
43  return $fieldName;
44  }
45  $fieldNameSegments = explode('[', $fieldName, 2);
46  $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']';
47  if (count($fieldNameSegments) > 1) {
48  $fieldName .= '[' . $fieldNameSegments[1];
49  }
50  return $fieldName;
51  }
52 
61  protected function renderHiddenIdentityField($object, $name) {
62  if ($object instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
63  $object = $object->_loadRealInstance();
64  }
65  if (!is_object($object)
66  || !($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject)
67  || ($object->_isNew() && !$object->_isClone())) {
68  return '';
69  }
70  // Intentionally NOT using PersistenceManager::getIdentifierByObject here!!
71  // Using that one breaks re-submission of data in forms in case of an error.
72  $identifier = $object->getUid();
73  if ($identifier === NULL) {
74  return chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10);
75  }
76  $name = $this->prefixFieldName($name) . '[__identity]';
78 
79  return chr(10) . '<input type="hidden" name="'. $name . '" value="' . $identifier .'" />' . chr(10);
80  }
81 
88  protected function registerFieldNameForFormTokenGeneration($fieldName) {
89  if ($this->viewHelperVariableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames')) {
90  $formFieldNames = $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames');
91  } else {
92  $formFieldNames = array();
93  }
94  $formFieldNames[] = $fieldName;
95  $this->viewHelperVariableContainer->addOrUpdate('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames', $formFieldNames);
96  }
97 }