‪TYPO3CMS  ‪main
InlineStackProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
32 {
38  protected ‪$inlineStructure = [];
39 
43  public function ‪initializeByGivenStructure(array $structure = [])
44  {
45  $this->inlineStructure = $structure;
46  }
47 
58  public function ‪initializeByParsingDomObjectIdString(string $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 (!isset($TSconfig['disabled']) || !$TSconfig['disabled']) {
82  $unstable['config'] = ‪FormEngineUtility::overrideFieldConf($unstable['config'], $TSconfig);
83  }
84 
85  // Extract FlexForm from field part (if any)
86  if (str_contains($unstable['field'], ':')) {
87  $fieldParts = ‪GeneralUtility::trimExplode(':', $unstable['field']);
88  $unstable['field'] = array_shift($fieldParts);
89  // FlexForm parts start with data:
90  if (!empty($fieldParts) && $fieldParts[0] === 'data') {
91  $unstable['flexform'] = $fieldParts;
92  }
93  }
94 
95  $this->inlineStructure['stable'][] = $unstable;
96  $unstable = [];
97  }
98  $unstable[$vector[$i % 3]] = $parts[$i];
99  }
100  if (!empty($unstable)) {
101  $this->inlineStructure['unstable'] = $unstable;
102  }
103  }
104  }
105 
113  public function ‪setAjaxConfiguration(array $config)
114  {
115  $level = $this->‪calculateStructureLevel(-1);
116  if (empty($config) || $level === false) {
117  return;
118  }
119  $current = &$this->inlineStructure['stable'][$level];
120  $current['config'] = $config;
121  }
122 
128  public function ‪getStructure()
129  {
131  }
132 
136  public function ‪pushStableStructureItem(array $structureItem = [])
137  {
138  $this->inlineStructure['stable'][] = $structureItem;
139  }
140 
146  public function ‪getCurrentStructureFormPrefix()
147  {
148  $current = $this->‪getStructureLevel(-1);
149  $inlineFormName = '';
150  // If there are still more inline levels available
151  if ($current !== false) {
152  $inlineFormName = 'data' . $this->‪getStructureItemName($current, 'Disposal_AttributeName');
153  }
154  return $inlineFormName;
155  }
156 
163  public function ‪getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
164  {
165  $current = $this->‪getStructureLevel(-1);
166  $inlineDomObjectId = '';
167  // If there are still more inline levels available
168  if ($current !== false) {
169  $inlineDomObjectId = 'data-' . $inlineFirstPid . '-' . $this->‪getStructurePath();
170  }
171  return $inlineDomObjectId;
172  }
173 
183  public function ‪getStructureLevel($level)
184  {
185  $level = $this->‪calculateStructureLevel($level);
186 
187  if ($level !== false) {
188  return $this->inlineStructure['stable'][$level];
189  }
190  return false;
191  }
192 
200  public function ‪getUnstableStructure()
201  {
202  if (!isset($this->inlineStructure['unstable'])) {
203  throw new \RuntimeException('No unstable inline structure found', 1428582655);
204  }
205  return $this->inlineStructure['unstable'];
206  }
207 
214  protected function ‪calculateStructureLevel($level)
215  {
216  $result = false;
217  $structureCount = $this->‪getStructureDepth();
218  if ($level < 0) {
219  $level = $structureCount + $level;
220  }
221  if ($level >= 0 && $level < $structureCount) {
222  $result = $level;
223  }
224  return $result;
225  }
226 
234  protected function ‪getStructurePath($structureDepth = -1)
235  {
236  $structureLevels = [];
237  $structureCount = $this->‪getStructureDepth();
238  if ($structureDepth < 0 || $structureDepth > $structureCount) {
239  $structureDepth = $structureCount;
240  }
241  for ($i = 1; $i <= $structureDepth; $i++) {
242  array_unshift($structureLevels, ($this->‪getStructureItemName($this->‪getStructureLevel(-$i) ?: [], 'Disposal_AttributeId') ?: []));
243  }
244  return implode('-', $structureLevels);
245  }
246 
253  public function ‪getStructureDepth()
254  {
255  if (!isset($this->inlineStructure['stable']) || !is_array($this->inlineStructure['stable'])) {
256  return 0;
257  }
258  return count($this->inlineStructure['stable']);
259  }
260 
268  protected function ‪getStructureItemName($levelData, $disposal = 'Disposal_AttributeId')
269  {
270  $name = null;
271 
272  if (is_array($levelData)) {
273  $parts = [$levelData['table'], $levelData['uid']];
274 
275  if (!empty($levelData['field'])) {
276  $parts[] = $levelData['field'];
277  }
278 
279  // Use in name attributes:
280  if ($disposal === 'Disposal_AttributeName') {
281  if (!empty($levelData['field']) && !empty($levelData['flexform']) && $this->‪getStructureLevel(-1) === $levelData) {
282  $parts[] = implode('][', $levelData['flexform']);
283  }
284  $name = '[' . implode('][', $parts) . ']';
285  // Use in object id attributes:
286  } else {
287  $name = implode('-', $parts);
288 
289  if (!empty($levelData['field']) && !empty($levelData['flexform'])) {
290  array_unshift($levelData['flexform'], $name);
291  $name = implode('---', $levelData['flexform']);
292  }
293  }
294  }
295 
296  return $name;
297  }
298 }
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getTSconfigForTableRow
‪static mixed getTSconfigForTableRow($table, $row, $field='')
Definition: FormEngineUtility.php:110
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\setAjaxConfiguration
‪setAjaxConfiguration(array $config)
Definition: InlineStackProcessor.php:112
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructure
‪array getStructure()
Definition: InlineStackProcessor.php:127
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureItemName
‪string getStructureItemName($levelData, $disposal='Disposal_AttributeId')
Definition: InlineStackProcessor.php:267
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureDomObjectIdPrefix
‪string getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
Definition: InlineStackProcessor.php:162
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByGivenStructure
‪initializeByGivenStructure(array $structure=[])
Definition: InlineStackProcessor.php:42
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility
Definition: FormEngineUtility.php:41
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\calculateStructureLevel
‪bool int calculateStructureLevel($level)
Definition: InlineStackProcessor.php:213
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureLevel
‪array false getStructureLevel($level)
Definition: InlineStackProcessor.php:182
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getUnstableStructure
‪array getUnstableStructure()
Definition: InlineStackProcessor.php:199
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructurePath
‪string getStructurePath($structureDepth=-1)
Definition: InlineStackProcessor.php:233
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\$inlineStructure
‪array $inlineStructure
Definition: InlineStackProcessor.php:37
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\pushStableStructureItem
‪pushStableStructureItem(array $structureItem=[])
Definition: InlineStackProcessor.php:135
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureFormPrefix
‪string getCurrentStructureFormPrefix()
Definition: InlineStackProcessor.php:145
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureDepth
‪int getStructureDepth()
Definition: InlineStackProcessor.php:252
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByParsingDomObjectIdString
‪initializeByParsingDomObjectIdString(string $domObjectId)
Definition: InlineStackProcessor.php:57
‪TYPO3\CMS\Backend\Form\InlineStackProcessor
Definition: InlineStackProcessor.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\overrideFieldConf
‪static array overrideFieldConf($fieldConfig, $TSconfig)
Definition: FormEngineUtility.php:79
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822