/** * Handle the action. * * @return void */ public function process() { $event = $this->getEvent(); if ($event->getAction()->getName() !== 'paste') { return; } $environment = $this->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $definition = $environment->getDataDefinition()->getBasicDefinition(); // Tree mode needs special handling. if ($this->needTreeModeShowAll($definition, $input)) { $this->callAction('showAll'); return; } // Check if it is a simple create-paste of a single model, if so, redirect to edit view. if ($this->isSimpleCreatePaste($clipboard, $environment->getDataDefinition()->getBasicDefinition()->getDataProvider())) { $this->callAction('create'); return; } $controller = $environment->getController(); $after = $this->modelIdFromParameter($input, 'after'); $into = $this->modelIdFromParameter($input, 'into'); $parentModelId = $this->modelIdFromParameter($input, 'pid'); $items = array(); $controller->applyClipboardActions(null, $after, $into, $parentModelId, null, $items); foreach ($items as $item) { $clipboard->remove($item); } $clipboard->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } $clipboardActionName = $this->translateActionName($actionName); if (!$clipboardActionName) { return; } if ('create' === $actionName) { if ($this->isAddingAllowed($environment)) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // Let the clipboard save it's values persistent. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * Handle the delete all action. * * @param ModelIdInterface[] $modelIds The list of model ids. * * @return void */ protected function handleCopyAllAction($modelIds) { if (ViewHelpers::getManualSortingProperty($this->getEnvironment())) { $clipboard = $this->getEnvironment()->getClipboard(); $parentId = $this->getParentId(); foreach ($modelIds as $modelId) { $item = new Item(Item::COPY, $parentId, $modelId); $clipboard->push($item); } $clipboard->saveTo($this->getEnvironment()); } else { $handler = new CopyHandler(); $handler->setEnvironment($this->getEnvironment()); foreach ($modelIds as $modelId) { $handler->copy($modelId); } } ViewHelpers::redirectHome($this->getEnvironment()); }
/** * {@inheritdoc} * * This performs redirectHome() upon successful execution and throws an exception otherwise. * * @throws DcGeneralRuntimeException When invalid parameters are encountered. */ public function paste(Action $action) { $environment = $this->getEnvironment(); $controller = $environment->getController(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $source = $input->getParameter('source') ? IdSerializer::fromSerialized($input->getParameter('source')) : null; $after = $input->getParameter('after') ? IdSerializer::fromSerialized($input->getParameter('after')) : $input->getParameter('after'); $into = $input->getParameter('into') ? IdSerializer::fromSerialized($input->getParameter('into')) : null; $parentModelId = $input->getParameter('pid') ? IdSerializer::fromSerialized($input->getParameter('pid')) : null; $items = array(); $models = $controller->applyClipboardActions($source, $after, $into, $parentModelId, null, $items); if (!$source) { $clipboard->clear()->saveTo($environment); } /** @var ItemInterface[] $items */ if (1 === count($items) && ItemInterface::CREATE === $items[0]->getAction()) { $addToUrlEvent = new AddToUrlEvent('act=edit&id=' . ModelId::fromModel($models->get(0))->getSerialized()); $environment->getEventDispatcher()->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl()); $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent); return; } ViewHelpers::redirectHome($environment); }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } $clipboardActionName = $this->translateActionName($actionName); if (!$clipboardActionName) { return; } if ('create' === $actionName) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after attribute, a handler can pick it up. if (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after')) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // Let the clipboard save it's values persistent. // TODO remove clear and allow adding multiple items // Clipboard get cleared twice so far if being in create mode and partially in others. Don't know why it's here. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * {@inheritdoc} */ public function process() { if ($this->getEvent()->getAction()->getName() !== 'delete') { return; } $environment = $this->getEnvironment(); $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id')); // Guard that we are in the preloaded environment. Otherwise checking the data definition could belong to // another model. $this->guardValidEnvironment($modelId); // Only edit mode is supported. Trigger an edit action. if ($this->isEditOnlyResponse()) { return; } // We want a redirect here if not deletable. $this->guardIsDeletable($modelId, true); $this->delete($modelId); ViewHelpers::redirectHome($this->environment); }
/** * Check the get parameters if there is any node toggling. * * CAUTION: If there has been any action, the browser will get redirected and the script therefore exited. * * @return void */ private function handleNodeStateChanges() { $input = $this->getEnvironment()->getInputProvider(); if (($modelId = $input->getParameter('ptg')) && ($providerName = $input->getParameter('provider'))) { $states = $this->getTreeNodeStates(); // Check if the open/close all has been triggered or just a model. if ($modelId == 'all') { if ($states->isAllOpen()) { $states->resetAll(); } $states->setAllOpen($states->isAllOpen()); } else { $this->toggleModel($providerName, $modelId); } ViewHelpers::redirectHome($this->environment); } }