‪TYPO3CMS  9.5
InlineStackProcessor.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 
19 
29 {
35  protected ‪$inlineStructure = [];
36 
42  public function ‪initializeByGivenStructure(array $structure = [])
43  {
44  $this->inlineStructure = $structure;
45  }
46 
57  public function ‪initializeByParsingDomObjectIdString($domObjectId)
58  {
59  $unstable = [];
60  $vector = ['table', 'uid', 'field'];
61 
62  // Substitute FlexForm addition and make parsing a bit easier
63  $domObjectId = str_replace('---', ':', $domObjectId);
64  // The starting pattern of an object identifier (e.g. "data-<firstPidValue>-<anything>)
65  $pattern = '/^data' . '-' . '(.+?)' . '-' . '(.+)$/';
66 
67  if (preg_match($pattern, $domObjectId, $match)) {
68  $inlineFirstPid = $match[1];
69  $parts = explode('-', $match[2]);
70  $partsCnt = count($parts);
71  for ($i = 0; $i < $partsCnt; $i++) {
72  if ($i > 0 && $i % 3 == 0) {
73  // Load the TCA configuration of the table field and store it in the stack
74  // @todo: This TCA loading here must fall - config sub-array shouldn't exist at all!
75  $unstable['config'] = ‪$GLOBALS['TCA'][$unstable['table']]['columns'][$unstable['field']]['config'] ?? [];
76  // Fetch TSconfig:
77  // @todo: aaargs ;)
78  $TSconfig = ‪FormEngineUtility::getTSconfigForTableRow($unstable['table'], ['uid' => $unstable['uid'], 'pid' => $inlineFirstPid], $unstable['field']);
79  // Override TCA field config by TSconfig:
80  if (!isset($TSconfig['disabled']) || !$TSconfig['disabled']) {
81  $unstable['config'] = ‪FormEngineUtility::overrideFieldConf($unstable['config'], $TSconfig);
82  }
83 
84  // Extract FlexForm from field part (if any)
85  if (strpos($unstable['field'], ':') !== false) {
86  $fieldParts = GeneralUtility::trimExplode(':', $unstable['field']);
87  $unstable['field'] = array_shift($fieldParts);
88  // FlexForm parts start with data:
89  if (!empty($fieldParts) && $fieldParts[0] === 'data') {
90  $unstable['flexform'] = $fieldParts;
91  }
92  }
93 
94  $this->inlineStructure['stable'][] = $unstable;
95  $unstable = [];
96  }
97  $unstable[$vector[$i % 3]] = $parts[$i];
98  }
99  if (!empty($unstable)) {
100  $this->inlineStructure['unstable'] = $unstable;
101  }
102  }
103  }
104 
112  public function ‪injectAjaxConfiguration(array $config)
113  {
114  $level = $this->‪calculateStructureLevel(-1);
115  if (empty($config) || $level === false) {
116  return;
117  }
118  $current = &$this->inlineStructure['stable'][$level];
119  $current['config'] = $config;
120  }
121 
127  public function ‪getStructure()
128  {
130  }
131 
137  public function ‪pushStableStructureItem(array $structureItem = [])
138  {
139  $this->inlineStructure['stable'][] = $structureItem;
140  }
141 
147  public function ‪getCurrentStructureFormPrefix()
148  {
149  $current = $this->‪getStructureLevel(-1);
150  $inlineFormName = '';
151  // If there are still more inline levels available
152  if ($current !== false) {
153  $inlineFormName = 'data' . $this->‪getStructureItemName($current, 'Disposal_AttributeName');
154  }
155  return $inlineFormName;
156  }
157 
164  public function ‪getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
165  {
166  $current = $this->‪getStructureLevel(-1);
167  $inlineDomObjectId = '';
168  // If there are still more inline levels available
169  if ($current !== false) {
170  $inlineDomObjectId = 'data' . '-' . $inlineFirstPid . '-' . $this->‪getStructurePath();
171  }
172  return $inlineDomObjectId;
173  }
174 
184  public function ‪getStructureLevel($level)
185  {
186  $level = $this->‪calculateStructureLevel($level);
187 
188  if ($level !== false) {
189  return $this->inlineStructure['stable'][$level];
190  }
191  return false;
192  }
193 
201  public function ‪getUnstableStructure()
202  {
203  if (!isset($this->inlineStructure['unstable'])) {
204  throw new \RuntimeException('No unstable inline structure found', 1428582655);
205  }
206  return $this->inlineStructure['unstable'];
207  }
208 
215  protected function ‪calculateStructureLevel($level)
216  {
217  $result = false;
218  $structureCount = $this->‪getStructureDepth();
219  if ($level < 0) {
220  $level = $structureCount + $level;
221  }
222  if ($level >= 0 && $level < $structureCount) {
223  $result = $level;
224  }
225  return $result;
226  }
227 
235  protected function ‪getStructurePath($structureDepth = -1)
236  {
237  $structureLevels = [];
238  $structureCount = $this->‪getStructureDepth();
239  if ($structureDepth < 0 || $structureDepth > $structureCount) {
240  $structureDepth = $structureCount;
241  }
242  for ($i = 1; $i <= $structureDepth; $i++) {
243  array_unshift($structureLevels, $this->‪getStructureItemName($this->‪getStructureLevel(-$i), 'Disposal_AttributeId'));
244  }
245  return implode('-', $structureLevels);
246  }
247 
254  public function ‪getStructureDepth()
255  {
256  if (!isset($this->inlineStructure['stable']) || !is_array($this->inlineStructure['stable'])) {
257  return 0;
258  }
259  return count($this->inlineStructure['stable']);
260  }
261 
269  protected function ‪getStructureItemName($levelData, $disposal = 'Disposal_AttributeId')
270  {
271  $name = null;
272 
273  if (is_array($levelData)) {
274  $parts = [$levelData['table'], $levelData['uid']];
275 
276  if (!empty($levelData['field'])) {
277  $parts[] = $levelData['field'];
278  }
279 
280  // Use in name attributes:
281  if ($disposal === 'Disposal_AttributeName') {
282  if (!empty($levelData['field']) && !empty($levelData['flexform']) && $this->‪getStructureLevel(-1) === $levelData) {
283  $parts[] = implode('][', $levelData['flexform']);
284  }
285  $name = '[' . implode('][', $parts) . ']';
286  // Use in object id attributes:
287  } else {
288  $name = implode('-', $parts);
289 
290  if (!empty($levelData['field']) && !empty($levelData['flexform'])) {
291  array_unshift($levelData['flexform'], $name);
292  $name = implode('---', $levelData['flexform']);
293  }
294  }
295  }
296 
297  return $name;
298  }
299 }
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getTSconfigForTableRow
‪static mixed getTSconfigForTableRow($table, $row, $field='')
Definition: FormEngineUtility.php:96
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:3
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\injectAjaxConfiguration
‪injectAjaxConfiguration(array $config)
Definition: InlineStackProcessor.php:111
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructure
‪array getStructure()
Definition: InlineStackProcessor.php:126
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureItemName
‪string getStructureItemName($levelData, $disposal='Disposal_AttributeId')
Definition: InlineStackProcessor.php:268
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureDomObjectIdPrefix
‪string getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
Definition: InlineStackProcessor.php:163
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByGivenStructure
‪initializeByGivenStructure(array $structure=[])
Definition: InlineStackProcessor.php:41
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility
Definition: FormEngineUtility.php:38
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\calculateStructureLevel
‪bool int calculateStructureLevel($level)
Definition: InlineStackProcessor.php:214
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getUnstableStructure
‪array getUnstableStructure()
Definition: InlineStackProcessor.php:200
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructurePath
‪string getStructurePath($structureDepth=-1)
Definition: InlineStackProcessor.php:234
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\$inlineStructure
‪array $inlineStructure
Definition: InlineStackProcessor.php:34
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureLevel
‪array getStructureLevel($level)
Definition: InlineStackProcessor.php:183
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\pushStableStructureItem
‪pushStableStructureItem(array $structureItem=[])
Definition: InlineStackProcessor.php:136
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureFormPrefix
‪string getCurrentStructureFormPrefix()
Definition: InlineStackProcessor.php:146
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureDepth
‪int getStructureDepth()
Definition: InlineStackProcessor.php:253
‪TYPO3\CMS\Backend\Form\InlineStackProcessor
Definition: InlineStackProcessor.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByParsingDomObjectIdString
‪initializeByParsingDomObjectIdString($domObjectId)
Definition: InlineStackProcessor.php:56
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\overrideFieldConf
‪static array overrideFieldConf($fieldConfig, $TSconfig)
Definition: FormEngineUtility.php:65