[TASK] Add more fixers for php-cs-fixer
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Model / Configuration.php
1 <?php
2 namespace TYPO3\CMS\Form\Domain\Model;
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 * The Configuration model is a high-level API
19 * for the underlying TypoScript configuration.
20 */
21 class Configuration
22 {
23 /**
24 * @var string
25 */
26 const DISABLE_CONTENT_ELEMENT_RENDERING = 'disableContentElement';
27
28 /**
29 * @var string
30 */
31 const DEFAULT_THEME_NAME = 'Default';
32
33 /**
34 * @return Configuration
35 */
36 public static function create()
37 {
38 return \TYPO3\CMS\Form\Utility\FormUtility::getObjectManager()->get(self::class);
39 }
40
41 /**
42 * @var array
43 */
44 protected $typoScript = [];
45
46 /**
47 * @var bool
48 */
49 protected $contentElementRendering = false;
50
51 /**
52 * @var string
53 */
54 protected $prefix = 'form';
55
56 /**
57 * @var string
58 */
59 protected $themeName = '';
60
61 /**
62 * @var \TYPO3\CMS\Form\Domain\Repository\TypoScriptRepository
63 */
64 protected $typoScriptRepository;
65
66 /**
67 * @param \TYPO3\CMS\Form\Domain\Repository\TypoScriptRepository $typoScriptRepository
68 * @return void
69 */
70 public function injectTypoScriptRepository(\TYPO3\CMS\Form\Domain\Repository\TypoScriptRepository $typoScriptRepository)
71 {
72 $this->typoScriptRepository = $typoScriptRepository;
73 }
74
75 /**
76 * @return array
77 */
78 public function getTypoScript()
79 {
80 return $this->typoScript;
81 }
82
83 /**
84 * @param array $typoScript
85 * @return Configuration
86 */
87 public function setTypoScript(array $typoScript)
88 {
89 $this->typoScript = $typoScript;
90 $this->update();
91 return $this;
92 }
93
94 public function getContentElementRendering()
95 {
96 return $this->contentElementRendering;
97 }
98
99 /**
100 * @param $contentElementRendering
101 * @return Configuration
102 */
103 public function setContentElementRendering($contentElementRendering)
104 {
105 $this->contentElementRendering = (bool)$contentElementRendering;
106 return $this;
107 }
108
109 /**
110 * @return string
111 */
112 public function getPrefix()
113 {
114 return $this->prefix;
115 }
116
117 /**
118 * @param string $prefix
119 * @return Configuration
120 */
121 public function setPrefix($prefix)
122 {
123 $this->prefix = (string)$prefix;
124 return $this;
125 }
126
127 /**
128 * @return string
129 */
130 public function getThemeName()
131 {
132 return $this->themeName;
133 }
134
135 /**
136 * @param string $themeName
137 * @return Configuration
138 */
139 public function setThemeName($themeName = '')
140 {
141 if ($themeName === '') {
142 $themeName = static::DEFAULT_THEME_NAME;
143 }
144 $this->themeName = $themeName;
145 return $this;
146 }
147
148 /**
149 * Updates the local properties - called after
150 * new TypoScript has been assigned in this object.
151 */
152 protected function update()
153 {
154 // Determine content rendering mode. If activated, cObject and stdWrap can be
155 // used to execute various processes that must not be allowed on TypoScript
156 // that has been created by non-privileged backend users (= insecure TypoScript)
157 $this->setContentElementRendering(
158 empty($this->typoScript[static::DISABLE_CONTENT_ELEMENT_RENDERING])
159 );
160 // Determine the HTML form element prefix to distinguish
161 // different form components on the same page in the frontend
162 if (!empty($this->typoScript['prefix'])) {
163 $this->setPrefix($this->typoScript['prefix']);
164 }
165 // Set the theme name
166 if (!empty($this->typoScript['themeName'])) {
167 $this->setThemeName($this->typoScript['themeName']);
168 } elseif (!empty($this->typoScriptRepository->getModelConfigurationByScope('FORM', 'themeName'))) {
169 $this->setThemeName($this->typoScriptRepository->getModelConfigurationByScope('FORM', 'themeName'));
170 } else {
171 $this->setThemeName(static::DEFAULT_THEME_NAME);
172 }
173 }
174 }