[TASK] Organize TSconfig structure
[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 class FormUtility implements \TYPO3\CMS\Core\SingletonInterface {
21
22 /**
23 * @var array
24 */
25 protected $formObjects = array();
26
27 /**
28 * Gets a singleton instance of this object.
29 *
30 * @return \TYPO3\CMS\Form\Utility\FormUtility
31 */
32 static public function getInstance() {
33 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(__CLASS__);
34 }
35
36 /**
37 * Initializes this object.
38 */
39 public function __construct() {
40 $this->setFormObjects(array(
41 'BUTTON',
42 'CHECKBOX',
43 'CHECKBOXGROUP',
44 'FIELDSET',
45 'FILEUPLOAD',
46 'FORM',
47 'FORM_INT',
48 'HEADER',
49 'HIDDEN',
50 'IMAGEBUTTON',
51 'OPTGROUP',
52 'OPTION',
53 'PASSWORD',
54 'RADIO',
55 'RADIOGROUP',
56 'RESET',
57 'SELECT',
58 'SUBMIT',
59 'TEXTAREA',
60 'TEXTBLOCK',
61 'TEXTLINE'
62 ));
63 }
64
65 /**
66 * Gets the available form objects.
67 *
68 * @return array
69 */
70 public function getFormObjects() {
71 return $this->formObjects;
72 }
73
74 /**
75 * Sets the available form objects.
76 *
77 * @param array $formObjects
78 * @return void
79 */
80 public function setFormObjects(array $formObjects) {
81 $this->formObjects = $formObjects;
82 }
83
84 /**
85 * Initializes the available form objects.
86 *
87 * @return \TYPO3\CMS\Form\Utility\FormUtility
88 */
89 public function initializeFormObjects() {
90 // Assign new FORM objects
91 foreach ($this->getFormObjects() as $formObject) {
92 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'][] = array(
93 $formObject,
94 \TYPO3\CMS\Form\Controller\FormController::class
95 );
96 }
97 return $this;
98 }
99
100 /**
101 * Initializes the Page TSconfig properties.
102 *
103 * @return \TYPO3\CMS\Form\Utility\FormUtility
104 */
105 public function initializePageTsConfig() {
106 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:form/Configuration/PageTSconfig/modWizards.ts">');
107 return $this;
108 }
109
110 /**
111 * Gets the last part of the current object's class name.
112 * e.g. for '\TYPO3\CMS\Form\View\Confirmation\Additional\AdditionalElementView' it will be 'Additional'
113 *
114 * @param object $object The object to be used
115 * @param bool $lowercase Whether to convert to lowercase
116 * @return string
117 */
118 public function getLastPartOfClassName($object, $lowercase = FALSE) {
119 $lastPart = preg_replace('/^.*\\\\([^\\\\]+?)(Additional|Attribute|Json|Element|View)+$/', '${1}', get_class($object), 1);
120 if ($lowercase) {
121 $lastPart = strtolower($lastPart);
122 }
123 return $lastPart;
124 }
125
126 }