|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * Abstract Form View Helper. Bundles functionality related to direct property access of objects in other Form ViewHelpers. 00025 * 00026 * If you set the "property" attribute to the name of the property to resolve from the object, this class will 00027 * automatically set the name and value of a form element. 00028 * 00029 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00030 */ 00031 abstract class Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper { 00032 00033 /** 00034 * @var Tx_Extbase_Persistence_ManagerInterface 00035 */ 00036 protected $persistenceManager; 00037 00038 /** 00039 * Injects the FLOW3 Persistence Manager 00040 * 00041 * @param Tx_Extbase_Persistence_ManagerInterface $persistenceManager 00042 * @return void 00043 * @author Robert Lemke <robert@typo3.org> 00044 */ 00045 public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) { 00046 $this->persistenceManager = $persistenceManager; 00047 } 00048 00049 /** 00050 * Prefixes / namespaces the given name with the form field prefix 00051 * 00052 * @param string $fieldName field name to be prefixed 00053 * @return string namespaced field name 00054 */ 00055 protected function prefixFieldName($fieldName) { 00056 if ($fieldName === NULL || $fieldName === '') { 00057 return ''; 00058 } 00059 if (!$this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')) { 00060 return $fieldName; 00061 } 00062 $fieldNamePrefix = (string)$this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix'); 00063 if ($fieldNamePrefix === '') { 00064 return $fieldName; 00065 } 00066 $fieldNameSegments = explode('[', $fieldName, 2); 00067 $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']'; 00068 if (count($fieldNameSegments) > 1) { 00069 $fieldName .= '[' . $fieldNameSegments[1]; 00070 } 00071 return $fieldName; 00072 } 00073 00074 /** 00075 * Renders a hidden form field containing the technical identity of the given object. 00076 * 00077 * @return string A hidden field containing the Identity (UID in FLOW3, uid in Extbase) of the given object or NULL if the object is unknown to the persistence framework 00078 * @author Robert Lemke <robert@typo3.org> 00079 * @author Karsten Dambekalns <karsten@typo3.org> 00080 * @author Bastian Waidelich <bastian@typo3.org> 00081 * @see Tx_Fluid_MVC_Controller_Argument::setValue() 00082 */ 00083 protected function renderHiddenIdentityField($object, $name) { 00084 if (!is_object($object) 00085 || !($object instanceof Tx_Extbase_DomainObject_AbstractDomainObject) 00086 || ($object->_isNew() && !$object->_isClone()) 00087 ){ 00088 return ''; 00089 } 00090 // Intentionally NOT using PersistenceManager::getIdentifierByObject here!! 00091 // Using that one breaks re-submission of data in forms in case of an error. 00092 $identifier = $object->getUid(); 00093 if ($identifier === NULL) { 00094 return chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10); 00095 } 00096 $name = $this->prefixFieldName($name) . '[__identity]'; 00097 $this->registerFieldNameForFormTokenGeneration($name); 00098 00099 return chr(10) . '<input type="hidden" name="'. $name . '" value="' . $identifier .'" />' . chr(10); 00100 } 00101 00102 /** 00103 * Register a field name for inclusion in the HMAC / Form Token generation 00104 * 00105 * @param string $fieldName name of the field to register 00106 * @return void 00107 * @author Sebastian Kurfürst <sebastian@typo3.org> 00108 * @author Bastian Waidelich <bastian@typo3.org> 00109 */ 00110 protected function registerFieldNameForFormTokenGeneration($fieldName) { 00111 if ($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_FormViewHelper', 'formFieldNames')) { 00112 $formFieldNames = $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'formFieldNames'); 00113 } else { 00114 $formFieldNames = array(); 00115 } 00116 $formFieldNames[] = $fieldName; 00117 $this->viewHelperVariableContainer->addOrUpdate('Tx_Fluid_ViewHelpers_FormViewHelper', 'formFieldNames', $formFieldNames); 00118 } 00119 } 00120 00121 ?>
1.8.0