TYPO3 CMS  TYPO3_6-2
ElementEntityProcessor.php
Go to the documentation of this file.
1 <?php
3 
20 
25 
29  protected $workspace;
30 
34  protected $dataHandler;
35 
41  public function setWorkspace($workspace) {
42  $this->workspace = (int)$workspace;
43  }
44 
50  public function getWorkspace() {
51  return $this->workspace;
52  }
53 
57  public function getDataHandler() {
58  if (!isset($this->dataHandler)) {
59  $this->dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
60  }
61  return $this->dataHandler;
62  }
63 
70  public function transformDependentElementsToUseLiveId(array $elements) {
71  $transformedElements = array();
73  foreach ($elements as $element) {
74  $elementName = ElementEntity::getIdentifier($element->getTable(), $element->getDataValue('liveId'));
75  $transformedElements[$elementName] = $element;
76  }
77  return $transformedElements;
78  }
79 
89  public function createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName) {
90  $fieldConfiguration = BackendUtility::getTcaFieldConfiguration($caller->getTable(), $callerArguments['field']);
91  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && !GeneralUtility::inList('field,list', $this->getDataHandler()->getInlineFieldType($fieldConfiguration)))) {
93  }
94  return NULL;
95  }
96 
106  public function createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName) {
107  $fieldConfiguration = BackendUtility::getTcaFieldConfiguration($callerArguments['table'], $callerArguments['field']);
108  if (!$fieldConfiguration || ($fieldConfiguration['type'] !== 'flex' && !GeneralUtility::inList('field,list', $this->getDataHandler()->getInlineFieldType($fieldConfiguration)))) {
110  }
111  return NULL;
112  }
113 
124  public function createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName) {
125  $response = $this->createNewDependentElementChildReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
126  if (empty($response)) {
127  $record = BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
128  if (!VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
129  $response = ElementEntity::RESPONSE_Skip;
130  }
131  }
132  return $response;
133  }
134 
145  public function createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName) {
146  $response = $this->createNewDependentElementParentReferenceCallback($callerArguments, $targetArgument, $caller, $eventName);
147  if (empty($response)) {
148  $record = BackendUtility::getRecord($callerArguments['table'], $callerArguments['id']);
149  if (!VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
150  $response = ElementEntity::RESPONSE_Skip;
151  }
152  }
153  return $response;
154  }
155 
166  public function createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName) {
168  $caller->setInvalid(TRUE);
169  return;
170  }
171 
172  $versionRecord = $caller->getRecord();
173  // If version record does not exist, it probably has been deleted (cleared from workspace), this means,
174  // that the reference index still has an old reference pointer, which is "fine" for deleted parents
175  if (empty($versionRecord)) {
176  throw new \RuntimeException(
177  'Element "' . $caller::getIdentifier($caller->getTable(), $caller->getId()) . '" does not exist',
178  1393960943
179  );
180  }
181  // If version is on live workspace, but the pid is negative, mark the record as invalid.
182  // This happens if a change has been discarded (clearWSID) - it will be removed from the command map.
183  if ((int)$versionRecord['t3ver_wsid'] === 0 && (int)$versionRecord['pid'] === -1) {
184  $caller->setDataValue('liveId', $caller->getId());
185  $caller->setInvalid(TRUE);
186  return;
187  }
188  if ($caller->hasDataValue('liveId') === FALSE) {
189  // Set the original uid from the version record
190  if (!empty($versionRecord['t3ver_oid']) && (int)$versionRecord['pid'] === -1 && (int)$versionRecord['t3ver_wsid'] === $this->getWorkspace()) {
191  $caller->setDataValue('liveId', $versionRecord['t3ver_oid']);
192  // The current version record is actually a live record or an accordant placeholder for live
193  } elseif ((int)$versionRecord['t3ver_wsid'] === 0 || (int)$versionRecord['pid'] !== -1) {
194  $caller->setDataValue('liveId', $caller->getId());
196  $this->getWorkspace(),
197  $caller->getTable(),
198  $caller->getId(),
199  'uid,t3ver_state'
200  );
201  // Set version uid to caller, most likely it's a delete placeholder
202  // for a child record that is not recognized in the reference index
203  if (!empty($versionRecord['uid'])) {
204  $caller->setId($versionRecord['uid']);
205  // If no version could be determined, mark record as invalid
206  // (thus, it will be removed from the command map)
207  } else {
208  $caller->setInvalid(TRUE);
209  }
210  // In case of an unexpected record state, mark the record as invalid
211  } else {
212  $caller->setInvalid(TRUE);
213  }
214  }
215  }
216 
217 }
createClearDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
static getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields=' *')
createNewDependentElementChildReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
createNewDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
createClearDependentElementParentReferenceCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
static getTcaFieldConfiguration($table, $field)
createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)