[TASK] Refactor code of new form system extension
[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 'HIDDEN',
61 'IMAGEBUTTON',
62 'OPTGROUP',
63 'OPTION',
64 'PASSWORD',
65 'RADIO',
66 'RADIOGROUP',
67 'RESET',
68 'SELECT',
69 'SUBMIT',
70 'TEXTAREA',
71 'TEXTLINE',
72 )
73 );
74 }
75
76 /**
77 * Gets the available form objects.
78 *
79 * @return array
80 */
81 public function getFormObjects() {
82 return $this->formObjects;
83 }
84
85 /**
86 * Sets the available form objects.
87 *
88 * @param array $formObjects
89 * @return void
90 */
91 public function setFormObjects(array $formObjects) {
92 $this->formObjects = $formObjects;
93 }
94
95 /**
96 * Initializes the available form objects.
97 *
98 * @return tx_form_Common
99 */
100 public function initializeFormObjects() {
101 // Assign new FORM objects
102 foreach ($this->getFormObjects() as $formObject) {
103 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'][] = array(
104 $formObject,
105 'EXT:form/Classes/Controller/Form.php:&tx_form_Controller_Form'
106 );
107 }
108
109 return $this;
110 }
111
112 /**
113 * Initializes the Page TSconfig properties.
114 *
115 * @return tx_form_Common
116 */
117 public function initializePageTsConfig() {
118 t3lib_extMgm::addPageTSConfig(
119 '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:form/Resources/Private/Configuration/PageTSconfig/modWizards.ts">'
120 );
121
122 return $this;
123 }
124
125 /**
126 * Gets the last part of the current object's class name.
127 * e.g. for 'tx_form_View_Confirmation_Additional' it will be 'Additional'
128 *
129 * @param object $object The object to be used
130 * @param boolean $lowercase Whether to convert to lowercase
131 * @return string
132 */
133 public function getLastPartOfClassName($object, $lowercase = FALSE) {
134 $lastPart = preg_replace('/.*_([^_]*)$/', '${1}', get_class($object), 1);
135
136 if ($lowercase) {
137 $lastPart = strtolower($lastPart);
138 }
139
140 return $lastPart;
141 }
142 }
143 ?>