/**
  * Callback to add additional data to new elements created in the dependency resolver utility.
  *
  * @throws \RuntimeException
  * @param ElementEntity $caller
  * @param array $callerArguments
  * @param array $targetArgument
  * @param string $eventName
  * @return void
  */
 public function createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
 {
     if (!BackendUtility::isTableWorkspaceEnabled($caller->getTable())) {
         $caller->setInvalid(true);
         return;
     }
     $versionRecord = $caller->getRecord();
     // If version record does not exist, it probably has been deleted (cleared from workspace), this means,
     // that the reference index still has an old reference pointer, which is "fine" for deleted parents
     if (empty($versionRecord)) {
         throw new \RuntimeException('Element "' . $caller::getIdentifier($caller->getTable(), $caller->getId()) . '" does not exist', 1393960943);
     }
     // If version is on live workspace, but the pid is negative, mark the record as invalid.
     // This happens if a change has been discarded (clearWSID) - it will be removed from the command map.
     if ((int) $versionRecord['t3ver_wsid'] === 0 && (int) $versionRecord['pid'] === -1) {
         $caller->setDataValue('liveId', $caller->getId());
         $caller->setInvalid(true);
         return;
     }
     if ($caller->hasDataValue('liveId') === false) {
         // Set the original uid from the version record
         if (!empty($versionRecord['t3ver_oid']) && (int) $versionRecord['pid'] === -1 && (int) $versionRecord['t3ver_wsid'] === $this->getWorkspace()) {
             $caller->setDataValue('liveId', $versionRecord['t3ver_oid']);
             // The current version record is actually a live record or an accordant placeholder for live
         } elseif ((int) $versionRecord['t3ver_wsid'] === 0 || (int) $versionRecord['pid'] !== -1) {
             $caller->setDataValue('liveId', $caller->getId());
             $versionRecord = BackendUtility::getWorkspaceVersionOfRecord($this->getWorkspace(), $caller->getTable(), $caller->getId(), 'uid,t3ver_state');
             // Set version uid to caller, most likely it's a delete placeholder
             // for a child record that is not recognized in the reference index
             if (!empty($versionRecord['uid'])) {
                 $caller->setId($versionRecord['uid']);
                 // If no version could be determined, mark record as invalid
                 // (thus, it will be removed from the command map)
             } else {
                 $caller->setInvalid(true);
             }
             // In case of an unexpected record state, mark the record as invalid
         } else {
             $caller->setInvalid(true);
         }
     }
 }