‪TYPO3CMS  10.4
ElementEntityProcessor.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 
22 
27 {
31  protected ‪$workspace;
32 
36  protected ‪$dataHandler;
37 
43  public function ‪setWorkspace(‪$workspace)
44  {
45  $this->workspace = (int)‪$workspace;
46  }
47 
53  public function ‪getWorkspace()
54  {
55  return ‪$this->workspace;
56  }
57 
61  public function ‪getDataHandler()
62  {
63  if (!isset($this->dataHandler)) {
64  $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class);
65  }
66  return ‪$this->dataHandler;
67  }
68 
75  public function ‪transformDependentElementsToUseLiveId(array $elements)
76  {
77  $transformedElements = [];
79  foreach ($elements as $element) {
80  $elementName = ‪ElementEntity::getIdentifier($element->getTable(), $element->getDataValue('liveId'));
81  $transformedElements[$elementName] = $element;
82  }
83  return $transformedElements;
84  }
85 
95  public function ‪createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
96  {
97  // skip children in case ancestor is invalid
98  if ($caller->‪isInvalid()) {
100  }
101  $fieldConfiguration = ‪BackendUtility::getTcaFieldConfiguration($caller->‪getTable(), $callerArguments['field']);
102  $inlineFieldType = $this->‪getDataHandler()->‪getInlineFieldType($fieldConfiguration);
103  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && $inlineFieldType !== 'field' && $inlineFieldType !== 'list')) {
105  }
106  return null;
107  }
108 
118  public function ‪createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
119  {
120  $fieldConfiguration = ‪BackendUtility::getTcaFieldConfiguration($callerArguments['table'], $callerArguments['field']);
121  $inlineFieldType = $this->‪getDataHandler()->‪getInlineFieldType($fieldConfiguration);
122  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && $inlineFieldType !== 'field' && $inlineFieldType !== 'list')) {
124  }
125  return null;
126  }
127 
138  public function ‪createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
139  {
140  $response = $this->‪createNewDependentElementChildReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
141  if (empty($response)) {
142  $record = ‪BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
143  if (!‪VersionState::cast($record['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
145  }
146  }
147  return $response;
148  }
149 
160  public function ‪createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
161  {
162  $response = $this->‪createNewDependentElementParentReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
163  if (empty($response)) {
164  $record = ‪BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
165  if (!‪VersionState::cast($record['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
167  }
168  }
169  return $response;
170  }
171 
181  public function ‪createNewDependentElementCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
182  {
184  $caller->‪setInvalid(true);
185  return;
186  }
187 
188  $versionRecord = $caller->‪getRecord();
189  // If version record does not exist, it probably has been deleted (cleared from workspace), this means,
190  // that the reference index still has an old reference pointer, which is "fine" for deleted parents
191  if (empty($versionRecord)) {
192  throw new \RuntimeException(
193  'Element "' . $caller::getIdentifier($caller->‪getTable(), $caller->‪getId()) . '" does not exist',
194  1393960943
195  );
196  }
197 
198  $deleteFieldName = ‪$GLOBALS['TCA'][$caller->‪getTable()]['ctrl']['delete'] ?? null;
199  // If version is on live workspace, but an "offline" ID is set, mark the record as invalid.
200  // This happens if a change has been discarded (clearWSID) - it will be removed from the command map.
201  if (
202  (int)$versionRecord['t3ver_oid'] > 0 && (
203  (int)$versionRecord['t3ver_wsid'] === 0 // behavior prior to v10.1 (backward compatibility)
204  || !empty($deleteFieldName) && (int)$versionRecord['t3ver_wsid'] === $this->‪getWorkspace()
205  && (int)$versionRecord[$deleteFieldName] > 0 // behavior since v10.1
206  )
207  ) {
208  $caller->‪setDataValue('liveId', $caller->‪getId());
209  $caller->‪setInvalid(true);
210  return;
211  }
212  if ($caller->‪hasDataValue('liveId') === false) {
213  // Set the original uid from the version record
214  if (!empty($versionRecord['t3ver_oid']) && (int)$versionRecord['t3ver_wsid'] === $this->‪getWorkspace()) {
215  $caller->‪setDataValue('liveId', $versionRecord['t3ver_oid']);
216  } elseif ((int)$versionRecord['t3ver_wsid'] === 0 || (int)$versionRecord['t3ver_oid'] === 0) {
217  // The current version record is actually a live record or an accordant placeholder for live
218  $caller->‪setDataValue('liveId', $caller->‪getId());
220  $this->‪getWorkspace(),
221  $caller->‪getTable(),
222  $caller->‪getId(),
223  'uid,t3ver_state'
224  );
225  // Set version uid to caller, most likely it's a delete placeholder
226  // for a child record that is not recognized in the reference index
227  if (!empty($versionRecord['uid'])) {
228  $caller->‪setId($versionRecord['uid']);
229  } else {
230  // If no version could be determined, mark record as invalid
231  // (thus, it will be removed from the command map)
232  $caller->‪setInvalid(true);
233  }
234  } else {
235  // In case of an unexpected record state, mark the record as invalid
236  $caller->‪setInvalid(true);
237  }
238  }
239  }
240 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\setWorkspace
‪setWorkspace($workspace)
Definition: ElementEntityProcessor.php:41
‪TYPO3\CMS\Backend\Utility\BackendUtility\getTcaFieldConfiguration
‪static array getTcaFieldConfiguration($table, $field)
Definition: BackendUtility.php:4033
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createClearDependentElementParentReferenceCallback
‪string null createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:158
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getId
‪int getId()
Definition: ElementEntity.php:125
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\RESPONSE_Skip
‪const RESPONSE_Skip
Definition: ElementEntity.php:31
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementParentReferenceCallback
‪string null createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:116
‪TYPO3\CMS\Core\DataHandling\DataHandler\getInlineFieldType
‪string bool getInlineFieldType($conf)
Definition: DataHandler.php:8293
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity
Definition: ElementEntity.php:25
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\getDataHandler
‪DataHandler getDataHandler()
Definition: ElementEntityProcessor.php:59
‪TYPO3\CMS\Core\Versioning\VersionState\DELETE_PLACEHOLDER
‪const DELETE_PLACEHOLDER
Definition: VersionState.php:55
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\hasDataValue
‪bool hasDataValue($key)
Definition: ElementEntity.php:182
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementCallback
‪createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:179
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setInvalid
‪setInvalid($invalid)
Definition: ElementEntity.php:97
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getRecord
‪array getRecord()
Definition: ElementEntity.php:406
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled
‪static bool isTableWorkspaceEnabled($table)
Definition: BackendUtility.php:4021
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createClearDependentElementChildReferenceCallback
‪string null createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:136
‪TYPO3\CMS\Workspaces\Dependency
Definition: DependencyEntityFactory.php:16
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\isInvalid
‪bool isInvalid()
Definition: ElementEntity.php:105
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\transformDependentElementsToUseLiveId
‪array transformDependentElementsToUseLiveId(array $elements)
Definition: ElementEntityProcessor.php:73
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getWorkspaceVersionOfRecord
‪static array bool getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields=' *')
Definition: BackendUtility.php:3705
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementChildReferenceCallback
‪string null createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:93
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor
Definition: ElementEntityProcessor.php:27
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setId
‪setId($id)
Definition: ElementEntity.php:135
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\$workspace
‪int $workspace
Definition: ElementEntityProcessor.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setDataValue
‪setDataValue($key, $value)
Definition: ElementEntity.php:171
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\$dataHandler
‪DataHandler $dataHandler
Definition: ElementEntityProcessor.php:34
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\getWorkspace
‪int getWorkspace()
Definition: ElementEntityProcessor.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getIdentifier
‪static string getIdentifier($table, $id)
Definition: ElementEntity.php:396
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getTable
‪string getTable()
Definition: ElementEntity.php:115