‪TYPO3CMS  10.4
TcaInlineExpandCollapseState.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 
26 {
33  public function ‪addData(array $result)
34  {
35  if (empty($result['inlineExpandCollapseStateArray'])) {
36  $fullInlineState = json_decode($this->‪getBackendUser()->uc['inlineView'] ?? null, true);
37  if (!is_array($fullInlineState)) {
38  $fullInlineState = [];
39  }
40  $inlineStateForTable = [];
41  if (!empty($result['inlineTopMostParentUid']) && !empty($result['inlineTopMostParentTableName'])) {
42  // Happens in inline ajax context, top parent uid and top parent table are set
43  if ($result['command'] !== 'new') {
44  $table = $result['inlineTopMostParentTableName'];
45  $uid = $result['inlineTopMostParentUid'];
46  if (!empty($fullInlineState[$table][$uid])) {
47  $inlineStateForTable = $fullInlineState[$table][$uid];
48  }
49  }
50  } else {
51  // Default case for a single record
52  if ($result['command'] !== 'new') {
53  $table = $result['tableName'];
54  $uid = $result['databaseRow']['uid'];
55  if (!empty($fullInlineState[$table][$uid])) {
56  $inlineStateForTable = $fullInlineState[$table][$uid];
57  }
58  }
59  }
60  $result['inlineExpandCollapseStateArray'] = $inlineStateForTable;
61  }
62 
63  if (!$result['isInlineChildExpanded']) {
64  // If the record is an inline child that is not expanded, it is not necessary to calculate all fields
65  $isExistingRecord = $result['command'] === 'edit';
66  $inlineConfig = $result['inlineParentConfig'];
67  $collapseAll = isset($inlineConfig['appearance']['collapseAll']) && $inlineConfig['appearance']['collapseAll'];
68  $expandAll = isset($inlineConfig['appearance']['collapseAll']) && !$inlineConfig['appearance']['collapseAll'];
69  $expandCollapseStateArray = $result['inlineExpandCollapseStateArray'];
70  $foreignTable = $result['inlineParentConfig']['foreign_table'];
71  $isExpandedByUcState = isset($expandCollapseStateArray[$foreignTable])
72  && is_array($expandCollapseStateArray[$foreignTable])
73  && in_array($result['databaseRow']['uid'], $expandCollapseStateArray[$foreignTable]) !== false;
74 
75  if (!$isExistingRecord || ($isExpandedByUcState && !$collapseAll) || $expandAll || $result['isInlineAjaxOpeningContext']) {
76  $result['isInlineChildExpanded'] = true;
77  }
78  }
79 
80  return $result;
81  }
82 
86  protected function ‪getBackendUser()
87  {
88  return ‪$GLOBALS['BE_USER'];
89  }
90 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineExpandCollapseState\addData
‪array addData(array $result)
Definition: TcaInlineExpandCollapseState.php:33
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineExpandCollapseState\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: TcaInlineExpandCollapseState.php:86
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineExpandCollapseState
Definition: TcaInlineExpandCollapseState.php:26