TYPO3 CMS  TYPO3_8-7
InlineStackProcessor.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form;
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 
30 {
36  protected $inlineStructure = [];
37 
43  public function initializeByGivenStructure(array $structure = [])
44  {
45  $this->inlineStructure = $structure;
46  }
47 
58  public function initializeByParsingDomObjectIdString($domObjectId)
59  {
60  $unstable = [];
61  $vector = ['table', 'uid', 'field'];
62 
63  // Substitute FlexForm addition and make parsing a bit easier
64  $domObjectId = str_replace('---', ':', $domObjectId);
65  // The starting pattern of an object identifier (e.g. "data-<firstPidValue>-<anything>)
66  $pattern = '/^data' . '-' . '(.+?)' . '-' . '(.+)$/';
67 
68  if (preg_match($pattern, $domObjectId, $match)) {
69  $inlineFirstPid = $match[1];
70  $parts = explode('-', $match[2]);
71  $partsCnt = count($parts);
72  for ($i = 0; $i < $partsCnt; $i++) {
73  if ($i > 0 && $i % 3 == 0) {
74  // Load the TCA configuration of the table field and store it in the stack
75  // @todo: This TCA loading here must fall - config sub-array shouldn't exist at all!
76  $unstable['config'] = $GLOBALS['TCA'][$unstable['table']]['columns'][$unstable['field']]['config'];
77  // Fetch TSconfig:
78  // @todo: aaargs ;)
79  $TSconfig = FormEngineUtility::getTSconfigForTableRow($unstable['table'], ['uid' => $unstable['uid'], 'pid' => $inlineFirstPid], $unstable['field']);
80  // Override TCA field config by TSconfig:
81  if (!$TSconfig['disabled']) {
82  $unstable['config'] = FormEngineUtility::overrideFieldConf($unstable['config'], $TSconfig);
83  }
84  $unstable['localizationMode'] = BackendUtility::getInlineLocalizationMode($unstable['table'], $unstable['config']);
85 
86  // Extract FlexForm from field part (if any)
87  if (strpos($unstable['field'], ':') !== false) {
88  $fieldParts = GeneralUtility::trimExplode(':', $unstable['field']);
89  $unstable['field'] = array_shift($fieldParts);
90  // FlexForm parts start with data:
91  if (!empty($fieldParts) && $fieldParts[0] === 'data') {
92  $unstable['flexform'] = $fieldParts;
93  }
94  }
95 
96  $this->inlineStructure['stable'][] = $unstable;
97  $unstable = [];
98  }
99  $unstable[$vector[$i % 3]] = $parts[$i];
100  }
101  if (!empty($unstable)) {
102  $this->inlineStructure['unstable'] = $unstable;
103  }
104  }
105  }
106 
114  public function injectAjaxConfiguration(array $config)
115  {
116  $level = $this->calculateStructureLevel(-1);
117  if (empty($config) || $level === false) {
118  return;
119  }
120  $current = &$this->inlineStructure['stable'][$level];
121  $current['config'] = $config;
122  $current['localizationMode'] = BackendUtility::getInlineLocalizationMode(
123  $current['table'],
124  $current['config']
125  );
126  }
127 
133  public function getStructure()
134  {
135  return $this->inlineStructure;
136  }
137 
143  public function pushStableStructureItem(array $structureItem = [])
144  {
145  $this->inlineStructure['stable'][] = $structureItem;
146  }
147 
154  {
155  $current = $this->getStructureLevel(-1);
156  $inlineFormName = '';
157  // If there are still more inline levels available
158  if ($current !== false) {
159  $inlineFormName = 'data' . $this->getStructureItemName($current, 'Disposal_AttributeName');
160  }
161  return $inlineFormName;
162  }
163 
170  public function getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
171  {
172  $current = $this->getStructureLevel(-1);
173  $inlineDomObjectId = '';
174  // If there are still more inline levels available
175  if ($current !== false) {
176  $inlineDomObjectId = 'data' . '-' . $inlineFirstPid . '-' . $this->getStructurePath();
177  }
178  return $inlineDomObjectId;
179  }
180 
190  public function getStructureLevel($level)
191  {
192  $level = $this->calculateStructureLevel($level);
193 
194  if ($level !== false) {
195  return $this->inlineStructure['stable'][$level];
196  }
197  return false;
198  }
199 
207  public function getUnstableStructure()
208  {
209  if (!isset($this->inlineStructure['unstable'])) {
210  throw new \RuntimeException('No unstable inline structure found', 1428582655);
211  }
212  return $this->inlineStructure['unstable'];
213  }
214 
221  protected function calculateStructureLevel($level)
222  {
223  $result = false;
224  $structureCount = $this->getStructureDepth();
225  if ($level < 0) {
226  $level = $structureCount + $level;
227  }
228  if ($level >= 0 && $level < $structureCount) {
229  $result = $level;
230  }
231  return $result;
232  }
233 
241  protected function getStructurePath($structureDepth = -1)
242  {
243  $structureLevels = [];
244  $structureCount = $this->getStructureDepth();
245  if ($structureDepth < 0 || $structureDepth > $structureCount) {
246  $structureDepth = $structureCount;
247  }
248  for ($i = 1; $i <= $structureDepth; $i++) {
249  array_unshift($structureLevels, $this->getStructureItemName($this->getStructureLevel(-$i), 'Disposal_AttributeId'));
250  }
251  return implode('-', $structureLevels);
252  }
253 
260  public function getStructureDepth()
261  {
262  if (!isset($this->inlineStructure['stable']) || !is_array($this->inlineStructure['stable'])) {
263  return 0;
264  }
265  return count($this->inlineStructure['stable']);
266  }
267 
275  protected function getStructureItemName($levelData, $disposal = 'Disposal_AttributeId')
276  {
277  $name = null;
278 
279  if (is_array($levelData)) {
280  $parts = [$levelData['table'], $levelData['uid']];
281 
282  if (!empty($levelData['field'])) {
283  $parts[] = $levelData['field'];
284  }
285 
286  // Use in name attributes:
287  if ($disposal === 'Disposal_AttributeName') {
288  if (!empty($levelData['field']) && !empty($levelData['flexform']) && $this->getStructureLevel(-1) === $levelData) {
289  $parts[] = implode('][', $levelData['flexform']);
290  }
291  $name = '[' . implode('][', $parts) . ']';
292  // Use in object id attributes:
293  } else {
294  $name = implode('-', $parts);
295 
296  if (!empty($levelData['field']) && !empty($levelData['flexform'])) {
297  array_unshift($levelData['flexform'], $name);
298  $name = implode('---', $levelData['flexform']);
299  }
300  }
301  }
302 
303  return $name;
304  }
305 }
static getTSconfigForTableRow($table, $row, $field='')
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
getStructureItemName($levelData, $disposal='Disposal_AttributeId')
static getInlineLocalizationMode($table, $fieldOrConfig)
static static overrideFieldConf($fieldConfig, $TSconfig)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']