‪TYPO3CMS  10.4
InlineStackProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
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 (!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 (strpos($unstable['field'], ':') !== false) {
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 ‪injectAjaxConfiguration(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 
138  public function ‪pushStableStructureItem(array $structureItem = [])
139  {
140  $this->inlineStructure['stable'][] = $structureItem;
141  }
142 
148  public function ‪getCurrentStructureFormPrefix()
149  {
150  $current = $this->‪getStructureLevel(-1);
151  $inlineFormName = '';
152  // If there are still more inline levels available
153  if ($current !== false) {
154  $inlineFormName = 'data' . $this->‪getStructureItemName($current, 'Disposal_AttributeName');
155  }
156  return $inlineFormName;
157  }
158 
165  public function ‪getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
166  {
167  $current = $this->‪getStructureLevel(-1);
168  $inlineDomObjectId = '';
169  // If there are still more inline levels available
170  if ($current !== false) {
171  $inlineDomObjectId = 'data-' . $inlineFirstPid . '-' . $this->‪getStructurePath();
172  }
173  return $inlineDomObjectId;
174  }
175 
185  public function ‪getStructureLevel($level)
186  {
187  $level = $this->‪calculateStructureLevel($level);
188 
189  if ($level !== false) {
190  return $this->inlineStructure['stable'][$level];
191  }
192  return false;
193  }
194 
202  public function ‪getUnstableStructure()
203  {
204  if (!isset($this->inlineStructure['unstable'])) {
205  throw new \RuntimeException('No unstable inline structure found', 1428582655);
206  }
207  return $this->inlineStructure['unstable'];
208  }
209 
216  protected function ‪calculateStructureLevel($level)
217  {
218  $result = false;
219  $structureCount = $this->‪getStructureDepth();
220  if ($level < 0) {
221  $level = $structureCount + $level;
222  }
223  if ($level >= 0 && $level < $structureCount) {
224  $result = $level;
225  }
226  return $result;
227  }
228 
236  protected function ‪getStructurePath($structureDepth = -1)
237  {
238  $structureLevels = [];
239  $structureCount = $this->‪getStructureDepth();
240  if ($structureDepth < 0 || $structureDepth > $structureCount) {
241  $structureDepth = $structureCount;
242  }
243  for ($i = 1; $i <= $structureDepth; $i++) {
244  array_unshift($structureLevels, $this->‪getStructureItemName($this->‪getStructureLevel(-$i), 'Disposal_AttributeId'));
245  }
246  return implode('-', $structureLevels);
247  }
248 
255  public function ‪getStructureDepth()
256  {
257  if (!isset($this->inlineStructure['stable']) || !is_array($this->inlineStructure['stable'])) {
258  return 0;
259  }
260  return count($this->inlineStructure['stable']);
261  }
262 
270  protected function ‪getStructureItemName($levelData, $disposal = 'Disposal_AttributeId')
271  {
272  $name = null;
273 
274  if (is_array($levelData)) {
275  $parts = [$levelData['table'], $levelData['uid']];
276 
277  if (!empty($levelData['field'])) {
278  $parts[] = $levelData['field'];
279  }
280 
281  // Use in name attributes:
282  if ($disposal === 'Disposal_AttributeName') {
283  if (!empty($levelData['field']) && !empty($levelData['flexform']) && $this->‪getStructureLevel(-1) === $levelData) {
284  $parts[] = implode('][', $levelData['flexform']);
285  }
286  $name = '[' . implode('][', $parts) . ']';
287  // Use in object id attributes:
288  } else {
289  $name = implode('-', $parts);
290 
291  if (!empty($levelData['field']) && !empty($levelData['flexform'])) {
292  array_unshift($levelData['flexform'], $name);
293  $name = implode('---', $levelData['flexform']);
294  }
295  }
296  }
297 
298  return $name;
299  }
300 }
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getTSconfigForTableRow
‪static mixed getTSconfigForTableRow($table, $row, $field='')
Definition: FormEngineUtility.php:97
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\injectAjaxConfiguration
‪injectAjaxConfiguration(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:269
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureDomObjectIdPrefix
‪string getCurrentStructureDomObjectIdPrefix($inlineFirstPid)
Definition: InlineStackProcessor.php:164
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByGivenStructure
‪initializeByGivenStructure(array $structure=[])
Definition: InlineStackProcessor.php:42
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility
Definition: FormEngineUtility.php:39
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\calculateStructureLevel
‪bool int calculateStructureLevel($level)
Definition: InlineStackProcessor.php:215
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getUnstableStructure
‪array getUnstableStructure()
Definition: InlineStackProcessor.php:201
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructurePath
‪string getStructurePath($structureDepth=-1)
Definition: InlineStackProcessor.php:235
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\$inlineStructure
‪array $inlineStructure
Definition: InlineStackProcessor.php:35
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureLevel
‪array getStructureLevel($level)
Definition: InlineStackProcessor.php:184
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\pushStableStructureItem
‪pushStableStructureItem(array $structureItem=[])
Definition: InlineStackProcessor.php:137
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getCurrentStructureFormPrefix
‪string getCurrentStructureFormPrefix()
Definition: InlineStackProcessor.php:147
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\getStructureDepth
‪int getStructureDepth()
Definition: InlineStackProcessor.php:254
‪TYPO3\CMS\Backend\Form\InlineStackProcessor
Definition: InlineStackProcessor.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\InlineStackProcessor\initializeByParsingDomObjectIdString
‪initializeByParsingDomObjectIdString($domObjectId)
Definition: InlineStackProcessor.php:57
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\overrideFieldConf
‪static array overrideFieldConf($fieldConfig, $TSconfig)
Definition: FormEngineUtility.php:66