[~FEATURE] Fluid (ViewHelpers): Adjusted AbstractFormViewHelper to be able to namespa...
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / AbstractFormViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * Abstract Form View Helper. Bundles functionality related to direct property access of objects in other Form ViewHelpers.
25 *
26 * If you set the "property" attribute to the name of the property to resolve from the object, this class will
27 * automatically set the name and value of a form element.
28 *
29 * @version $Id: AbstractFormViewHelper.php 2968 2009-08-03 10:45:13Z sebastian $
30 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
31 * @scope prototype
32 */
33 abstract class Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper extends Tx_Fluid_Core_ViewHelper_TagBasedViewHelper {
34
35 /**
36 * @var \Tx_Extbase_Persistence_ManagerInterface
37 */
38 protected $persistenceManager;
39
40 /**
41 * Injects the FLOW3 Persistence Manager
42 *
43 * @param Tx_Extbase_Persistence_ManagerInterface $persistenceManager
44 * @return void
45 * @author Robert Lemke <robert@typo3.org>
46 */
47 public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) {
48 $this->persistenceManager = $persistenceManager;
49 }
50
51 /**
52 * Prefixes / namespaces the given name with the form field prefix
53 *
54 * @param string $name field name to be prefixed
55 * @return string namespaced field name
56 */
57 protected function prefixFieldName($fieldName) {
58 if ($fieldName === NULL || $fieldName === '') {
59 return '';
60 }
61 $fieldNamePrefix = (string)$this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix');
62 if ($fieldNamePrefix === '') {
63 return $fieldName;
64 }
65 $fieldNameSegments = explode('[', $fieldName, 2);
66 $fieldName = $fieldNamePrefix . '[' . $fieldNameSegments[0] . ']';
67 if (count($fieldNameSegments) > 1) {
68 $fieldName .= '[' . $fieldNameSegments[1];
69 }
70 return $fieldName;
71 }
72 }
73
74 ?>