‪TYPO3CMS  9.5
ElementEntityProcessor.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 
21 
26 {
30  protected ‪$workspace;
31 
35  protected ‪$dataHandler;
36 
42  public function ‪setWorkspace(‪$workspace)
43  {
44  $this->workspace = (int)‪$workspace;
45  }
46 
52  public function ‪getWorkspace()
53  {
54  return ‪$this->workspace;
55  }
56 
60  public function ‪getDataHandler()
61  {
62  if (!isset($this->dataHandler)) {
63  $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class);
64  }
65  return ‪$this->dataHandler;
66  }
67 
74  public function ‪transformDependentElementsToUseLiveId(array $elements)
75  {
76  $transformedElements = [];
78  foreach ($elements as $element) {
79  $elementName = ‪ElementEntity::getIdentifier($element->getTable(), $element->getDataValue('liveId'));
80  $transformedElements[$elementName] = $element;
81  }
82  return $transformedElements;
83  }
84 
94  public function ‪createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
95  {
96  $fieldConfiguration = ‪BackendUtility::getTcaFieldConfiguration($caller->‪getTable(), $callerArguments['field']);
97  $inlineFieldType = $this->‪getDataHandler()->‪getInlineFieldType($fieldConfiguration);
98  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && $inlineFieldType !== 'field' && $inlineFieldType !== 'list')) {
100  }
101  return null;
102  }
103 
113  public function ‪createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
114  {
115  $fieldConfiguration = ‪BackendUtility::getTcaFieldConfiguration($callerArguments['table'], $callerArguments['field']);
116  $inlineFieldType = $this->‪getDataHandler()->‪getInlineFieldType($fieldConfiguration);
117  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && $inlineFieldType !== 'field' && $inlineFieldType !== 'list')) {
119  }
120  return null;
121  }
122 
133  public function ‪createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
134  {
135  $response = $this->‪createNewDependentElementChildReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
136  if (empty($response)) {
137  $record = ‪BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
138  if (!‪VersionState::cast($record['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
140  }
141  }
142  return $response;
143  }
144 
155  public function ‪createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
156  {
157  $response = $this->‪createNewDependentElementParentReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
158  if (empty($response)) {
159  $record = ‪BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
160  if (!‪VersionState::cast($record['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
162  }
163  }
164  return $response;
165  }
166 
176  public function ‪createNewDependentElementCallback(array $callerArguments, array $targetArgument, ‪ElementEntity $caller, $eventName)
177  {
179  $caller->‪setInvalid(true);
180  return;
181  }
182 
183  $versionRecord = $caller->‪getRecord();
184  // If version record does not exist, it probably has been deleted (cleared from workspace), this means,
185  // that the reference index still has an old reference pointer, which is "fine" for deleted parents
186  if (empty($versionRecord)) {
187  throw new \RuntimeException(
188  'Element "' . $caller::getIdentifier($caller->‪getTable(), $caller->‪getId()) . '" does not exist',
189  1393960943
190  );
191  }
192  // If version is on live workspace, but the pid is negative, mark the record as invalid.
193  // This happens if a change has been discarded (clearWSID) - it will be removed from the command map.
194  if ((int)$versionRecord['t3ver_wsid'] === 0 && (int)$versionRecord['pid'] === -1) {
195  $caller->‪setDataValue('liveId', $caller->‪getId());
196  $caller->‪setInvalid(true);
197  return;
198  }
199  if ($caller->‪hasDataValue('liveId') === false) {
200  // Set the original uid from the version record
201  if (!empty($versionRecord['t3ver_oid']) && (int)$versionRecord['pid'] === -1 && (int)$versionRecord['t3ver_wsid'] === $this->‪getWorkspace()) {
202  $caller->‪setDataValue('liveId', $versionRecord['t3ver_oid']);
203  } elseif ((int)$versionRecord['t3ver_wsid'] === 0 || (int)$versionRecord['pid'] !== -1) {
204  // The current version record is actually a live record or an accordant placeholder for live
205  $caller->‪setDataValue('liveId', $caller->‪getId());
207  $this->‪getWorkspace(),
208  $caller->‪getTable(),
209  $caller->‪getId(),
210  'uid,t3ver_state'
211  );
212  // Set version uid to caller, most likely it's a delete placeholder
213  // for a child record that is not recognized in the reference index
214  if (!empty($versionRecord['uid'])) {
215  $caller->‪setId($versionRecord['uid']);
216  } else {
217  // If no version could be determined, mark record as invalid
218  // (thus, it will be removed from the command map)
219  $caller->‪setInvalid(true);
220  }
221  } else {
222  // In case of an unexpected record state, mark the record as invalid
223  $caller->‪setInvalid(true);
224  }
225  }
226  }
227 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\setWorkspace
‪setWorkspace($workspace)
Definition: ElementEntityProcessor.php:40
‪TYPO3\CMS\Backend\Utility\BackendUtility\getTcaFieldConfiguration
‪static array getTcaFieldConfiguration($table, $field)
Definition: BackendUtility.php:4505
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createClearDependentElementParentReferenceCallback
‪string null createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:153
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getId
‪int getId()
Definition: ElementEntity.php:124
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\RESPONSE_Skip
‪const RESPONSE_Skip
Definition: ElementEntity.php:30
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementParentReferenceCallback
‪string null createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:111
‪TYPO3\CMS\Core\DataHandling\DataHandler\getInlineFieldType
‪string bool getInlineFieldType($conf)
Definition: DataHandler.php:8501
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity
Definition: ElementEntity.php:24
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\getDataHandler
‪DataHandler getDataHandler()
Definition: ElementEntityProcessor.php:58
‪TYPO3\CMS\Core\Versioning\VersionState\DELETE_PLACEHOLDER
‪const DELETE_PLACEHOLDER
Definition: VersionState.php:54
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\hasDataValue
‪bool hasDataValue($key)
Definition: ElementEntity.php:181
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementCallback
‪createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:174
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setInvalid
‪setInvalid($invalid)
Definition: ElementEntity.php:96
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getRecord
‪array getRecord()
Definition: ElementEntity.php:405
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled
‪static bool isTableWorkspaceEnabled($table)
Definition: BackendUtility.php:4493
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createClearDependentElementChildReferenceCallback
‪string null createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:131
‪TYPO3\CMS\Workspaces\Dependency
Definition: DependencyEntityFactory.php:2
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\transformDependentElementsToUseLiveId
‪array transformDependentElementsToUseLiveId(array $elements)
Definition: ElementEntityProcessor.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getWorkspaceVersionOfRecord
‪static array bool getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields=' *')
Definition: BackendUtility.php:4166
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:23
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\createNewDependentElementChildReferenceCallback
‪string null createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
Definition: ElementEntityProcessor.php:92
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor
Definition: ElementEntityProcessor.php:26
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setId
‪setId($id)
Definition: ElementEntity.php:134
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\$workspace
‪int $workspace
Definition: ElementEntityProcessor.php:29
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\setDataValue
‪setDataValue($key, $value)
Definition: ElementEntity.php:170
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\$dataHandler
‪DataHandler $dataHandler
Definition: ElementEntityProcessor.php:33
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor\getWorkspace
‪int getWorkspace()
Definition: ElementEntityProcessor.php:50
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getIdentifier
‪static string getIdentifier($table, $id)
Definition: ElementEntity.php:395
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\getTable
‪string getTable()
Definition: ElementEntity.php:114