/** * Get the id which identifies the item in the clipboard. * * @return string */ public function getClipboardId() { if ($this->modelId) { return $this->getAction() . $this->modelId->getSerialized() . (($parentId = $this->getParentId()) ? $parentId->getSerialized() : 'null'); } else { return $this->getAction() . $this->getDataProviderName() . (($parentId = $this->getParentId()) ? $parentId->getSerialized() : 'null'); } }
/** * Fetch the model. * * @param ModelIdInterface $modelId The model id. * * @return ModelInterface * * @throws DcGeneralRuntimeException If no model are found. */ protected function fetchModel(ModelIdInterface $modelId) { $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName()); $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId())); if (!$model || !$model->getId()) { throw new DcGeneralRuntimeException('Could not load model with id ' . $modelId->getSerialized()); } return $model; }
/** * Guard that the environment is prepared for models data definition. * * @param ModelIdInterface $modelId The model id. * * @return void * * @throws DcGeneralRuntimeException If data provider name of modelId and definition does not match. */ protected function guardValidEnvironment(ModelIdInterface $modelId) { if ($this->getEnvironment()->getDataDefinition()->getName() !== $modelId->getDataProviderName()) { throw new DcGeneralRuntimeException(sprintf('Not able to perform action. Environment is not prepared for model "%s"', $modelId->getSerialized())); } }
/** * Retrieve the base data provider config for the current data definition. * * This includes parent filter when in parented list mode and the additional filters from the data definition. * * @param ModelIdInterface $parentId The optional parent to use. * * @return ConfigInterface */ public function getBaseConfig(ModelIdInterface $parentId = null) { $key = $parentId ? $parentId->getSerialized() : null; if (!isset($this->configs[$key])) { $this->configs[$key] = $this->buildBaseConfig($parentId); } return clone $this->configs[$key]; }
/** * Redirect to edit mask. * * @param EnvironmentInterface $environment The environment. * @param ModelIdInterface $copiedModelId The model id. * * @return void */ protected function redirect($environment, $copiedModelId) { // Build a clean url to remove the copy related arguments instad of using the AddToUrlEvent. $url = new BackendUrlBuilder(); $url->setPath('contao/main.php')->setQueryParameter('do', $environment->getInputProvider()->getParameter('do'))->setQueryParameter('table', $copiedModelId->getDataProviderName())->setQueryParameter('act', 'edit')->setQueryParameter('id', $copiedModelId->getSerialized()); $redirectEvent = new RedirectEvent($url->getUrl()); $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent); }
/** * {@inheritDoc} */ public function hasId(ModelIdInterface $modelId) { return isset($this->itemsByModelId[$modelId->getSerialized()]); }
/** * {@inheritdoc} */ public function getClipboardId() { return $this->getAction() . ($this->modelId ? $this->modelId->getSerialized() : 'null') . (($parentId = $this->getParentId()) ? $parentId->getSerialized() : 'null'); }
/** * {@inheritDoc} */ public function hasId(ModelIdInterface $modelId) { $serializedId = $modelId->getSerialized(); return isset($this->items[$serializedId]); }