FluidTYPO3\Flux\Service\ContentService::pasteAfter PHP Méthode

pasteAfter() public méthode

Paste one record after another record.
public pasteAfter ( string $command, array &$row, array $parameters, TYPO3\CMS\Core\DataHandling\DataHandler $tceMain ) : void
$command string The command which caused pasting - "copy" is targeted in order to determine "reference" pasting.
$row array The record to be pasted, by reference. Changes original $row
$parameters array List of parameters defining the paste operation target
$tceMain TYPO3\CMS\Core\DataHandling\DataHandler
Résultat void
    public function pasteAfter($command, array &$row, $parameters, DataHandler $tceMain)
    {
        $id = $row['uid'];
        $tablename = 'tt_content';
        $subCommand = NULL;
        $possibleArea = NULL;
        $parentUid = NULL;
        $relativeRecord = NULL;
        $possibleColPos = NULL;
        $nestedArguments = explode('-', $parameters[1]);
        $numberOfNestedArguments = count($nestedArguments);
        if (5 < $numberOfNestedArguments) {
            // Parameters were passed in a hyphen-glued string, created by Flux and passed into command.
            list($pid, $subCommand, $relativeUid, $parentUid, $possibleArea, $possibleColPos) = $nestedArguments;
            $parentUid = (int) $parentUid;
            // Parent into same grid results in endless loop
            if ('move' === $command && (int) $id === $parentUid && (int) $pid === (int) $row['pid']) {
                return;
            }
            $relativeUid = 0 - (int) $relativeUid;
            if (FALSE === empty($possibleArea)) {
                // Flux content area detected, override colPos to virtual Flux column number.
                // The $possibleColPos variable may or may not already be set but must be
                // overridden regardless.
                $possibleColPos = self::COLPOS_FLUXCONTENT;
            }
        } elseif (5 === $numberOfNestedArguments) {
            // Parameters are directly from TYPO3 and it almost certainly is a paste to page column.
            list(, $possibleColPos, , $relativeUid) = $nestedArguments;
            // $relativeUid parameter is not passed by every context. If not set and $pid is negative,
            // we must assume that the positive value of $pid is our relative target UID.
            $relativeUid = (int) (0 >= (int) $pid) ? $pid : $relativeUid;
        } elseif (2 === count($parameters) && is_numeric($parameters[1])) {
            // The most basic form of pasting: using the clickmenu to "paste after" sends only
            // two parameters and the second parameter is always numeric-only.
            list($tablename, $relativeUid) = $parameters;
        }
        // Creating the copy mapping array. Initial processing of all records being pasted,
        // either simply assigning them (copy action) or adjusting the copies to become
        // "insert records" elements which then render the original record (paste reference).
        $mappingArray = $this->createMappingArray($command, $subCommand, $id, $row, $tceMain);
        // If copying is performed relative to another element we must assume the values of
        // that element and use them as target relation values regardless of earlier parameters.
        if (0 > $relativeUid) {
            $relativeRecord = $this->loadRecordFromDatabase(abs($relativeUid));
            $possibleColPos = (int) $relativeRecord['colPos'];
            $possibleArea = $relativeRecord['tx_flux_column'];
            $parentUid = (int) $relativeRecord['tx_flux_parent'];
        }
        $this->applyMappingArray($mappingArray, $pid, $possibleColPos, $possibleArea, $parentUid, $tablename, $relativeUid, $relativeRecord, $tceMain);
    }

Usage Example

Exemple #1
0
 /**
  * Post-process a command executed on a record form the table this ConfigurationProvider
  * is attached to.
  *
  * @param string $command
  * @param integer $id
  * @param array $row
  * @param integer $relativeTo
  * @param DataHandler $reference
  * @return void
  */
 public function postProcessCommand($command, $id, array &$row, &$relativeTo, DataHandler $reference)
 {
     if (TRUE === self::shouldCallWithClassName(__CLASS__, __FUNCTION__, $id)) {
         parent::postProcessCommand($command, $id, $row, $relativeTo, $reference);
         $pasteCommands = array('copy', 'move');
         if (TRUE === in_array($command, $pasteCommands)) {
             $callback = $this->getCallbackCommand();
             if (TRUE === isset($callback['paste'])) {
                 $pasteCommand = $callback['paste'];
                 $parameters = explode('|', $pasteCommand);
                 $this->contentService->pasteAfter($command, $row, $parameters, $reference);
             } else {
                 $moveData = $this->getMoveData();
                 $this->contentService->moveRecord($row, $relativeTo, $moveData, $reference);
             }
         }
         self::trackMethodCallWithClassName(__CLASS__, __FUNCTION__, $id);
     }
 }