TYPO3 CMS  TYPO3_7-6
TypoScriptRepository.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
30 
34  protected $registeredElementTypes = [];
35 
39  protected $typoScriptParser;
40 
44  public function __construct()
45  {
46  $this->typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
47  $this->modelDefinitionTypoScript = $this->resolveTypoScriptReferences(
48  $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_form.']
49  );
51  }
52 
58  public function getRegisteredElementTypes()
59  {
61  }
62 
71  {
72  if (!empty($registeredElementTypes)) {
73  $this->registeredElementTypes = $registeredElementTypes;
74  } else {
75  if (!isset($this->modelDefinitionTypoScript['settings.']['registeredElements.'])) {
76  throw new \InvalidArgumentException('There are no registeredElements available.', 1441791615);
77  }
78  $registeredElements = $this->modelDefinitionTypoScript['settings.']['registeredElements.'];
79  foreach ($registeredElements as $registeredElementKey => $value) {
80  $registeredElementKey = rtrim($registeredElementKey, '.');
81  $this->registeredElementTypes[] = $registeredElementKey;
82  }
83  }
84  }
85 
93  public function getModelDefinedHtmlAttributes($elementType = '')
94  {
95  if ($elementType == '') {
96  return [];
97  }
98  $htmlAttributes = $this->getModelConfigurationByScope($elementType, 'htmlAttributes.');
99  if (is_array($htmlAttributes)) {
100  $htmlAttributes = array_fill_keys($htmlAttributes, null);
101  } else {
102  $htmlAttributes = [];
103  }
104  $defaultHtmlAttributeValues = $this->getModelConfigurationByScope($elementType, 'defaultHtmlAttributeValues.');
105  if (is_array($defaultHtmlAttributeValues)) {
106  foreach ($defaultHtmlAttributeValues as $defaultHtmlAttributeKey => $defaultHtmlAttributeValue) {
107  $htmlAttributes[$defaultHtmlAttributeKey] = $defaultHtmlAttributeValue;
108  }
109  } elseif (!is_array($htmlAttributes)) {
110  $htmlAttributes = [];
111  }
112  return $htmlAttributes;
113  }
114 
122  public function getDefaultFluidTemplate($elementType, $partialType = 'partialPath')
123  {
124  $partialPath = $this->getModelConfigurationByScope($elementType, $partialType);
125  if ($partialPath) {
126  return $partialPath;
127  }
128  return '';
129  }
130 
138  public function getModelConfigurationByScope($elementType, $scope)
139  {
140  if (isset($this->modelDefinitionTypoScript['settings.']['registeredElements.'][$elementType . '.'][$scope])) {
141  return $this->modelDefinitionTypoScript['settings.']['registeredElements.'][$elementType . '.'][$scope];
142  }
143  return null;
144  }
145 
154  public function getRegisteredClassName($name, $scope)
155  {
156  $name = strtolower($name);
157  if (isset($this->modelDefinitionTypoScript['settings.'][$scope . '.'][$name . '.']['className'])) {
158  return $this->modelDefinitionTypoScript['settings.'][$scope . '.'][$name . '.']['className'];
159  }
160  return null;
161  }
162 
170  protected function resolveTypoScriptReferences(array $typoScript)
171  {
172  $ignoreKeys = [];
173  foreach ($typoScript as $key => $value) {
174  if (isset($ignoreKeys[$key])) {
175  continue;
176  }
177  // i am a reference
178  if ($value[0] === '<') {
179  if (isset($typoScript[$key . '.'])) {
180  $oldTypoScript = $typoScript[$key . '.'];
181  } else {
182  $oldTypoScript = [];
183  }
184  // detect search level
185  $referencePath = trim(substr($value, 1));
186  $dotPosition = strpos($referencePath, '.');
187  if ($dotPosition === 0) {
188  // same position x =< .y
189  list($flatValue, $arrayValue) = $this->typoScriptParser->getVal(substr($referencePath, 1), $typoScript);
190  } else {
191  list($flatValue, $arrayValue) = $this->typoScriptParser->getVal($referencePath, $GLOBALS['TSFE']->tmpl->setup);
192  }
193  if (is_array($arrayValue)) {
194  $typoScript[$key . '.'] = array_replace_recursive($arrayValue, $oldTypoScript);
195  }
196  if ($flatValue[0] === '<') {
197  $temporaryTypoScript = [
198  'temp' => $flatValue,
199  'temp.' => $typoScript[$key . '.'],
200  ];
201  $temporaryTypoScript = $this->resolveTypoScriptReferences($temporaryTypoScript);
202  $arrayValue = array_replace_recursive($temporaryTypoScript['temp.'], $arrayValue, $oldTypoScript);
203  }
204  if (is_array($arrayValue)) {
205  $typoScript[$key . '.'] = array_replace_recursive($arrayValue, $oldTypoScript);
206  } elseif (isset($flatValue)) {
207  $typoScript[$key] = $flatValue;
208  } else {
209  $typoScript[$key . '.'] = $oldTypoScript;
210  }
211  }
212  // if array, then look deeper
213  if (isset($typoScript[$key . '.'])) {
214  $ignoreKeys[$key . '.'] = true;
215  $typoScript[$key . '.'] = $this->resolveTypoScriptReferences($typoScript[$key . '.']);
216  } elseif (is_array($typoScript[$key])) {
217  // if array, then look deeper
218  $typoScript[$key] = $this->resolveTypoScriptReferences($typoScript[$key]);
219  }
220  }
221  return $typoScript;
222  }
223 }
setRegisteredElementTypes(array $registeredElementTypes=[])
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getDefaultFluidTemplate($elementType, $partialType='partialPath')