[TASK] Move classAliasMaps into compatibility6 extension part 6
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Utility / FormUtility.php
1 <?php
2 namespace TYPO3\CMS\Form\Utility;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Common helper methods.
19 *
20 * @author Oliver Hader <oliver.hader@typo3.org>
21 */
22 class FormUtility implements \TYPO3\CMS\Core\SingletonInterface {
23
24 /**
25 * @var array
26 */
27 protected $formObjects = array();
28
29 /**
30 * Gets a singleton instance of this object.
31 *
32 * @return \TYPO3\CMS\Form\Utility\FormUtility
33 */
34 static public function getInstance() {
35 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(__CLASS__);
36 }
37
38 /**
39 * Initializes this object.
40 */
41 public function __construct() {
42 $this->setFormObjects(array(
43 'BUTTON',
44 'CHECKBOX',
45 'CHECKBOXGROUP',
46 'FIELDSET',
47 'FILEUPLOAD',
48 'FORM',
49 'FORM_INT',
50 'HEADER',
51 'HIDDEN',
52 'IMAGEBUTTON',
53 'OPTGROUP',
54 'OPTION',
55 'PASSWORD',
56 'RADIO',
57 'RADIOGROUP',
58 'RESET',
59 'SELECT',
60 'SUBMIT',
61 'TEXTAREA',
62 'TEXTBLOCK',
63 'TEXTLINE'
64 ));
65 }
66
67 /**
68 * Gets the available form objects.
69 *
70 * @return array
71 */
72 public function getFormObjects() {
73 return $this->formObjects;
74 }
75
76 /**
77 * Sets the available form objects.
78 *
79 * @param array $formObjects
80 * @return void
81 */
82 public function setFormObjects(array $formObjects) {
83 $this->formObjects = $formObjects;
84 }
85
86 /**
87 * Initializes the available form objects.
88 *
89 * @return \TYPO3\CMS\Form\Utility\FormUtility
90 */
91 public function initializeFormObjects() {
92 // Assign new FORM objects
93 foreach ($this->getFormObjects() as $formObject) {
94 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'][] = array(
95 $formObject,
96 'EXT:form/Classes/Controller/FormController.php:&TYPO3\\CMS\\Form\\Controller\\FormController'
97 );
98 }
99 return $this;
100 }
101
102 /**
103 * Initializes the Page TSconfig properties.
104 *
105 * @return \TYPO3\CMS\Form\Utility\FormUtility
106 */
107 public function initializePageTsConfig() {
108 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:form/Configuration/PageTS/modWizards.ts">');
109 return $this;
110 }
111
112 /**
113 * Gets the last part of the current object's class name.
114 * e.g. for '\TYPO3\CMS\Form\View\Confirmation\Additional\AdditionalElementView' it will be 'Additional'
115 *
116 * @param object $object The object to be used
117 * @param bool $lowercase Whether to convert to lowercase
118 * @return string
119 */
120 public function getLastPartOfClassName($object, $lowercase = FALSE) {
121 $lastPart = preg_replace('/^.*\\\\([^\\\\]+?)(Additional|Attribute|Json|Element|View)+$/', '${1}', get_class($object), 1);
122 if ($lowercase) {
123 $lastPart = strtolower($lastPart);
124 }
125 return $lastPart;
126 }
127
128 }