[BUGFIX] Validation for multiple forms on one page
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Common.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Oliver Hader <oliver.hader@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Common helper methods.
27 *
28 * @package TYPO3
29 * @subpackage form
30 * @author Oliver Hader <oliver.hader@typo3.org>
31 */
32 class tx_form_Common implements t3lib_Singleton {
33 /**
34 * @var array
35 */
36 protected $formObjects = array();
37
38 /**
39 * Gets a singleton instance of this object.
40 *
41 * @return tx_form_Common
42 */
43 public static function getInstance() {
44 return t3lib_div::makeInstance('tx_form_Common');
45 }
46
47 /**
48 * Initializes this object.
49 */
50 public function __construct() {
51 $this->setFormObjects(
52 array(
53 'BUTTON',
54 'CHECKBOX',
55 'CHECKBOXGROUP',
56 'FIELDSET',
57 'FILEUPLOAD',
58 'FORM',
59 'FORM_INT',
60 'HEADER',
61 'HIDDEN',
62 'IMAGEBUTTON',
63 'OPTGROUP',
64 'OPTION',
65 'PASSWORD',
66 'RADIO',
67 'RADIOGROUP',
68 'RESET',
69 'SELECT',
70 'SUBMIT',
71 'TEXTAREA',
72 'TEXTBLOCK',
73 'TEXTLINE',
74 )
75 );
76 }
77
78 /**
79 * Gets the available form objects.
80 *
81 * @return array
82 */
83 public function getFormObjects() {
84 return $this->formObjects;
85 }
86
87 /**
88 * Sets the available form objects.
89 *
90 * @param array $formObjects
91 * @return void
92 */
93 public function setFormObjects(array $formObjects) {
94 $this->formObjects = $formObjects;
95 }
96
97 /**
98 * Initializes the available form objects.
99 *
100 * @return tx_form_Common
101 */
102 public function initializeFormObjects() {
103 // Assign new FORM objects
104 foreach ($this->getFormObjects() as $formObject) {
105 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'][] = array(
106 $formObject,
107 'EXT:form/Classes/Controller/Form.php:&tx_form_Controller_Form'
108 );
109 }
110
111 return $this;
112 }
113
114 /**
115 * Initializes the Page TSconfig properties.
116 *
117 * @return tx_form_Common
118 */
119 public function initializePageTsConfig() {
120 t3lib_extMgm::addPageTSConfig(
121 '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:form/Configuration/PageTS/modWizards.ts">'
122 );
123
124 return $this;
125 }
126
127 /**
128 * Gets the last part of the current object's class name.
129 * e.g. for 'tx_form_View_Confirmation_Additional' it will be 'Additional'
130 *
131 * @param object $object The object to be used
132 * @param boolean $lowercase Whether to convert to lowercase
133 * @return string
134 */
135 public function getLastPartOfClassName($object, $lowercase = FALSE) {
136 $lastPart = preg_replace('/.*_([^_]*)$/', '${1}', get_class($object), 1);
137
138 if ($lowercase) {
139 $lastPart = strtolower($lastPart);
140 }
141
142 return $lastPart;
143 }
144 }
145 ?>