Beispiel #1
0
 /**
  * Handle AJAX calls to localize all records of a parent, localize a single record or to synchronize with the original language parent.
  *
  * @param string $type Defines the type 'localize' or 'synchronize' (string) or a single uid to be localized (int)
  * @param int $inlineFirstPid Inline first pid
  * @return array An array to be used for JSON
  */
 protected function renderInlineSynchronizeLocalizeRecords($type, $inlineFirstPid)
 {
     $jsonArray = FALSE;
     if (GeneralUtility::inList('localize,synchronize', $type) || MathUtility::canBeInterpretedAsInteger($type)) {
         $inlineRelatedRecordResolver = GeneralUtility::makeInstance(InlineRelatedRecordResolver::class);
         // The parent level:
         $parent = $this->inlineStackProcessor->getStructureLevel(-1);
         $current = $this->inlineStackProcessor->getUnstableStructure();
         $parentRecord = $inlineRelatedRecordResolver->getRecord($parent['table'], $parent['uid']);
         $cmd = array();
         $cmd[$parent['table']][$parent['uid']]['inlineLocalizeSynchronize'] = $parent['field'] . ',' . $type;
         /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
         $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
         $tce->stripslashes_values = FALSE;
         $tce->start(array(), $cmd);
         $tce->process_cmdmap();
         $oldItemList = $parentRecord[$parent['field']];
         $newItemList = $tce->registerDBList[$parent['table']][$parent['uid']][$parent['field']];
         $jsonArray = array('scriptCall' => array());
         $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($inlineFirstPid);
         $nameObjectForeignTable = $nameObject . '-' . $current['table'];
         // Get the name of the field pointing to the original record:
         $transOrigPointerField = $GLOBALS['TCA'][$current['table']]['ctrl']['transOrigPointerField'];
         // Get the name of the field used as foreign selector (if any):
         $foreignSelector = isset($parent['config']['foreign_selector']) && $parent['config']['foreign_selector'] ? $parent['config']['foreign_selector'] : FALSE;
         // Convert lists to array with uids of child records:
         $oldItems = FormEngineUtility::getInlineRelatedRecordsUidArray($oldItemList);
         $newItems = FormEngineUtility::getInlineRelatedRecordsUidArray($newItemList);
         // Determine the items that were localized or localized:
         $removedItems = array_diff($oldItems, $newItems);
         $localizedItems = array_diff($newItems, $oldItems);
         // Set the items that should be removed in the forms view:
         foreach ($removedItems as $item) {
             $jsonArray['scriptCall'][] = 'inline.deleteRecord(' . GeneralUtility::quoteJSvalue($nameObjectForeignTable . '-' . $item) . ', {forceDirectRemoval: true});';
         }
         // Set the items that should be added in the forms view:
         $html = '';
         $resultArray = NULL;
         // @todo: This should be another container ...
         foreach ($localizedItems as $item) {
             $row = $inlineRelatedRecordResolver->getRecord($current['table'], $item);
             $selectedValue = $foreignSelector ? GeneralUtility::quoteJSvalue($row[$foreignSelector]) : 'null';
             $options = $this->getConfigurationOptionsForChildElements();
             $options['databaseRow'] = array('uid' => $parent['uid']);
             $options['inlineFirstPid'] = $inlineFirstPid;
             $options['inlineRelatedRecordToRender'] = $row;
             $options['inlineRelatedRecordConfig'] = $parent['config'];
             $options['inlineStructure'] = $this->inlineStackProcessor->getStructure();
             $options['isAjaxContext'] = TRUE;
             $options['renderType'] = 'inlineRecordContainer';
             $childArray = $this->nodeFactory->create($options)->render();
             $html .= $childArray['html'];
             $childArray['html'] = '';
             // @todo: Obsolete if a container and copied from AbstractContainer for now
             if ($resultArray === NULL) {
                 $resultArray = $childArray;
             } else {
                 if (!empty($childArray['extJSCODE'])) {
                     $resultArray['extJSCODE'] .= LF . $childArray['extJSCODE'];
                 }
                 foreach ($childArray['additionalJavaScriptPost'] as $value) {
                     $resultArray['additionalJavaScriptPost'][] = $value;
                 }
                 foreach ($childArray['additionalJavaScriptSubmit'] as $value) {
                     $resultArray['additionalJavaScriptSubmit'][] = $value;
                 }
                 if (!empty($childArray['inlineData'])) {
                     $resultArrayInlineData = $resultArray['inlineData'];
                     $childInlineData = $childArray['inlineData'];
                     ArrayUtility::mergeRecursiveWithOverrule($resultArrayInlineData, $childInlineData);
                     $resultArray['inlineData'] = $resultArrayInlineData;
                 }
             }
             $jsonArray['scriptCall'][] = 'inline.memorizeAddRecord(' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) . ', ' . GeneralUtility::quoteJSvalue($item) . ', null, ' . $selectedValue . ');';
             // Remove possible virtual records in the form which showed that a child records could be localized:
             if (isset($row[$transOrigPointerField]) && $row[$transOrigPointerField]) {
                 $jsonArray['scriptCall'][] = 'inline.fadeAndRemove(' . GeneralUtility::quoteJSvalue($nameObjectForeignTable . '-' . $row[$transOrigPointerField] . '_div') . ');';
             }
         }
         if (!empty($html)) {
             $jsonArray['data'] = $html;
             array_unshift($jsonArray['scriptCall'], 'inline.domAddNewRecord(\'bottom\', ' . GeneralUtility::quoteJSvalue($nameObject . '_records') . ', ' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) . ', json.data);');
         }
         $this->mergeResult($resultArray);
         $jsonArray = $this->getInlineAjaxCommonScriptCalls($jsonArray, $parent['config'], $inlineFirstPid);
     }
     return $jsonArray;
 }