/** * Handle the "create variant" event. * * @param ActionEvent $event The action Event being executed. * * @return void * * @throws \RuntimeException When the base model can not be found. * @throws \InvalidArgumentException When the view in the environment is incompatible. */ public function handleCreateVariantAction(ActionEvent $event) { if ($event->getAction()->getName() != 'createvariant') { return; } $environment = $event->getEnvironment(); $view = $environment->getView(); $dataProvider = $environment->getDataProvider(); $inputProvider = $environment->getInputProvider(); $modelId = $inputProvider->hasParameter('id') ? ModelId::fromSerialized($inputProvider->getParameter('id')) : null; /** @var \MetaModels\DcGeneral\Data\Driver $dataProvider */ $model = $dataProvider->createVariant($dataProvider->getEmptyConfig()->setId($modelId->getId())); if ($model == null) { throw new \RuntimeException(sprintf('Could not find model with id %s for creating a variant.', $modelId)); } $metaModel = $this->getServiceContainer()->getFactory()->getMetaModel($model->getProviderName()); if (!$metaModel || !$metaModel->hasVariants()) { return; } $preFunction = function ($environment, $model) { /** @var EnvironmentInterface $environment */ $copyEvent = new PreCreateModelEvent($environment, $model); $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent); }; $postFunction = function ($environment, $model) { /** @var EnvironmentInterface $environment */ $copyEvent = new PostCreateModelEvent($environment, $model); $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent); }; if (!$view instanceof BackendViewInterface) { throw new \InvalidArgumentException('Invalid view registered in environment.'); } $editMask = new EditMask($view, $model, null, $preFunction, $postFunction, $this->breadcrumb($environment)); $event->setResponse($editMask->execute()); }
/** * @param ActionEvent $event * @param null $eventName * @param EventDispatcherInterface|null $eventDispatcher * @SuppressWarnings(PHPMD.LongVariable) * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function migrateRecipients(ActionEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) { $environment = $event->getEnvironment(); if ($environment->getDataDefinition()->getName() == 'mem_avisota_recipient_migrate' && $event->getAction()->getName() == 'migrate') { $input = $environment->getInputProvider(); $migrationId = 'AVISOTA_MIGRATE_RECIPIENT_' . $input->getParameter('migration'); if (!($migrationSettings = $this->getMigrationSettings($migrationId))) { return; } if (!($response = $this->generateResponse($environment, $migrationSettings, $migrationId))) { return; } $event->setResponse($response); $event->stopPropagation(); } }
public function generateStandardGroup(ActionEvent $event) { $action = $event->getAction(); $environment = $event->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); if ($dataDefinition->getName() !== 'orm_avisota_salutation_group' || $action->getName() !== 'generate') { return; } global $AVISOTA_SALUTATION; $eventDispatcher = $environment->getEventDispatcher(); $translator = $environment->getTranslator(); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_salutation')); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('orm_avisota_salutation_group')); $predefinedSalutations = $AVISOTA_SALUTATION; $entityDataProvider = new EntityDataProvider(); $entityDataProvider->setBaseConfig(array('source' => 'orm_avisota_salutation_group')); $entityManager = $entityDataProvider->getEntityManager(); $entityAccessor = $entityDataProvider->getEntityAccessor(); $salutationGroup = new \Avisota\Contao\Entity\SalutationGroup(); $salutationGroup->setTitle('Default group generated at ' . date(Config::get('datimFormat'))); $salutationGroup->setAlias(null); $sorting = 64; foreach ($predefinedSalutations as $index => $predefinedSalutation) { $salutation = new \Avisota\Contao\Entity\Salutation(); $entityAccessor->setProperties($salutation, $predefinedSalutation); $salutation->setSalutation($translator->translate($index, 'avisota_salutation')); $salutation->setSalutationGroup($salutationGroup); $salutation->setSorting($sorting); $salutationGroup->addSalutation($salutation); $sorting *= 2; } $entityManager->persist($salutationGroup); $entityManager->flush($salutationGroup); $sessionConfirm = Session::getInstance()->get('TL_CONFIRM'); if (!is_array($sessionConfirm)) { $sessionConfirm = (array) $sessionConfirm; } $sessionConfirm[] = $translator->translate('group_generated', 'orm_avisota_salutation_group'); Session::getInstance()->set('TL_CONFIRM', $sessionConfirm); Controller::redirect('contao/main.php?do=avisota_salutation'); }
public function handleAction(ActionEvent $event) { $environment = $event->getEnvironment(); if ($environment->getDataDefinition()->getName() != 'orm_avisota_queue') { return; } $action = $event->getAction(); if ($action->getName() == 'clear') { $input = $environment->getInputProvider(); $id = IdSerializer::fromSerialized($input->getParameter('id')); $repository = EntityHelper::getRepository('Avisota\\Contao:Queue'); /** @var \Avisota\Contao\Entity\Queue $queueData */ $queueData = $repository->find($id->getId()); /** @var QueueInterface $queue */ $queue = $GLOBALS['container'][sprintf('avisota.queue.%s', $queueData->getAlias())]; $queue->execute(new NullTransport()); $message = new AddMessageEvent(sprintf($GLOBALS['TL_LANG']['orm_avisota_queue']['queueCleared'], $queueData->getTitle()), AddMessageEvent::TYPE_CONFIRM); $event->getDispatcher()->dispatch(ContaoEvents::MESSAGE_ADD, $message); $redirect = new RedirectEvent('contao/main.php?do=avisota_queue&ref=' . TL_REFERER_ID); $event->getDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirect); } }
/** * Handle the given action. * * @param ActionEvent $event The event. * * @return void * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ public function handleAction(ActionEvent $event) { $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalDriver.css'; if ($event->getEnvironment()->getDataDefinition()->getName() !== $this->environment->getDataDefinition()->getName() || $event->getResponse() !== null) { return; } $action = $event->getAction(); $name = $action->getName(); switch ($name) { case 'select': // If no redirect happens, we want to display the showAll action. $name = 'showAll'; // No break here. // No break here. case 'create': case 'paste': case 'move': case 'undo': case 'edit': case 'showAll': $response = call_user_func_array(array($this, $name), array_merge(array($action), $action->getArguments())); $event->setResponse($response); break; case 'show': $handler = new ShowHandler(); $handler->handleEvent($event); break; default: } }
/** * Handle the add all action event. * * @param ActionEvent $event The event. * * @return void * * @throws \RuntimeException When the MetaModel can not be retrieved. * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ public function handleAddAll(ActionEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting') { return; } if ($event->getAction()->getName() !== 'dca_addall') { return; } $environment = $event->getEnvironment(); $dispatcher = $environment->getEventDispatcher(); $database = $this->getDatabase(); $input = $environment->getInputProvider(); $pid = ModelId::fromSerialized($input->getParameter('pid')); $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('default')); $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('tl_metamodel_dcasetting')); $referrer = new GetReferrerEvent(true, 'tl_metamodel_dcasetting'); $dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer); $template = new \BackendTemplate('be_autocreatepalette'); $template->cacheMessage = ''; $template->updateMessage = ''; $template->href = $referrer->getReferrerUrl(); $template->headline = $GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addall'][1]; // Severity is: error, confirm, info, new. $messages = array(); $palette = $database->prepare('SELECT * FROM tl_metamodel_dca WHERE id=?')->execute($pid->getId()); $metaModel = $this->getMetaModelById($palette->pid); if (!$metaModel) { throw new \RuntimeException('Could not retrieve MetaModel ' . $palette->pid); } $alreadyExisting = $database->prepare('SELECT * FROM tl_metamodel_dcasetting WHERE pid=?')->execute($pid->getId()); $knownAttributes = array(); $intMax = 128; while ($alreadyExisting->next()) { $knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row(); if ($intMax < $alreadyExisting->sorting) { $intMax = $alreadyExisting->sorting; } } $blnWantPerform = false; // Perform the labour work. if ($input->getValue('act') == 'perform') { $this->perform($metaModel, $knownAttributes, $intMax, $pid->getId(), $messages); } else { // Loop over all attributes now. foreach ($metaModel->getAttributes() as $attribute) { if (array_key_exists($attribute->get('id'), $knownAttributes)) { $messages[] = array('severity' => 'info', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_alreadycontained'], $attribute->getName())); } else { $messages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_willadd'], $attribute->getName())); $blnWantPerform = true; } } } if ($blnWantPerform) { $template->action = ampersand(\Environment::get('request')); $template->submit = $GLOBALS['TL_LANG']['MSC']['continue']; } else { $template->action = ampersand($referrer->getReferrerUrl()); $template->submit = $GLOBALS['TL_LANG']['MSC']['saveNclose']; } $template->error = $messages; $event->setResponse($template->parse()); }
/** * @param ActionEvent $event * @param $subscribeOptions * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.LongVariable) */ protected function handleSubscribeAction(ActionEvent $event, $subscribeOptions) { global $container, $TL_LANG; $environment = $event->getEnvironment(); $eventDispatcher = $environment->getEventDispatcher(); $inputProvider = $environment->getInputProvider(); $recipientRepository = EntityHelper::getRepository('Avisota\\Contao:Recipient'); $recipientId = $inputProvider->getParameter('recipient'); $recipient = $recipientRepository->find($recipientId); /** @var \Avisota\Contao\Entity\Recipient $recipient */ $mailingListRepository = EntityHelper::getRepository('Avisota\\Contao:MailingList'); $mailingListId = $inputProvider->getParameter('mailing-list'); $mailingList = $mailingListRepository->find($mailingListId); /** @var MailingList $mailingList */ /** @var SubscriptionManager $subscriptionManager */ $subscriptionManager = $container['avisota.subscription']; $subscriptionManager->subscribe($recipient, $mailingList, $subscribeOptions); $event = AddMessageEvent::createConfirm(sprintf($TL_LANG['orm_avisota_recipient']['subscribe'], $recipient->getEmail(), $mailingList ? $mailingList->getTitle() : $TL_LANG['orm_avisota_recipient']['subscription_global'])); $eventDispatcher->dispatch(ContaoEvents::MESSAGE_ADD, $event); $event = new RedirectEvent('contao/main.php?do=avisota_recipients#' . md5($recipient->getEmail())); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $event); }
/** * 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); }
/** * Initialize the panels for known actions so that they always know their state. * * @param ActionEvent $event The event. * * @return void */ public function initializePanels(ActionEvent $event) { if (!in_array($event->getAction()->getName(), array('copy', 'create', 'paste', 'delete', 'move', 'undo', 'edit', 'toggle', 'showAll', 'show'))) { return; } $environment = $event->getEnvironment(); $definition = $environment->getDataDefinition(); $view = $environment->getView(); if (!$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME) || !$view instanceof BaseView || !$view->getPanel()) { return; } /** @var Contao2BackendViewDefinitionInterface $backendDefinition */ $backendDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $listingConfig = $backendDefinition->getListingConfig(); $dataConfig = $environment->getBaseConfigRegistry()->getBaseConfig(); $panel = $view->getPanel(); ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig); }
public function handleAction(ActionEvent $event) { $environment = $event->getEnvironment(); if ($environment->getDataDefinition()->getName() != 'orm_avisota_recipient_source') { return; } $action = $event->getAction(); if ($action->getName() == 'list') { $response = $this->handleListAction($environment); $event->setResponse($response); } }
/** * @param ActionEvent $event * @param null $eventName * @param EventDispatcherInterface|null $eventDispatcher * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function injectAutocompleter(ActionEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) { global $container, $TL_CSS, $TL_JAVASCRIPT, $TL_MOOTOOLS; static $injected; if (!$injected && $event->getEnvironment()->getDataDefinition()->getName() == 'orm_avisota_salutation') { // backwards compatibility if (!$eventDispatcher) { /** @var EventDispatcher $eventDispatcher */ $eventDispatcher = $container['event-dispatcher']; } // load language file $loadEvent = new LoadLanguageFileEvent('orm_avisota_recipient'); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadEvent); // load data container $loadEvent = new LoadDataContainerEvent('orm_avisota_recipient'); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_LOAD_DATA_CONTAINER, $loadEvent); // inject styles $TL_CSS[] = 'assets/avisota/subscription-recipient/css/meio.autocomplete.css'; // inject scripts $TL_JAVASCRIPT[] = 'assets/avisota/subscription-recipient/js/Meio.Autocomplete.js'; $TL_JAVASCRIPT[] = 'assets/avisota/subscription-recipient/js/mootools-more-1.5.0.js'; // build container for orm_avisota_recipient $factory = DcGeneralFactory::deriveFromEnvironment($event->getEnvironment()); $factory->setContainerName('orm_avisota_recipient'); $containerFactory = $factory->createContainer(); // build token list $tokens = array(); foreach ($containerFactory->getPropertiesDefinition()->getPropertyNames() as $propertyName) { $tokens[] = array('value' => $propertyName, 'text' => sprintf('##%s##', $propertyName)); } $tokens = json_encode($tokens); // inject runtime code // TODO outsource in template $TL_MOOTOOLS[] = <<<EOF <script> var element = \$('ctrl_salutation'); if (element) { \tvar tokens = {$tokens}; \tvar options = { \t\tfilter: { \t\t\ttype: 'contains', \t\t\tpath: 'text' \t\t}, \t\ttokenize: { \t\t\tget: function(element) { \t\t\t\tvar text = element.get('value'); \t\t\t\tvar position = element.getCaretPosition(); \t\t\t\tvar start = text.lastIndexOf(' ', position - 1); \t\t\t\tvar end = text.indexOf(' ', position); \t\t\t\tif (start == -1) { \t\t\t\t\tstart = 0; \t\t\t\t} \t\t\t\telse { \t\t\t\t\tstart ++; \t\t\t\t} \t\t\t\tif (end == -1) { \t\t\t\t\tend = text.length; \t\t\t\t} \t\t\t\tvar token = text.substring(start, end); \t\t\t\tconsole.log('position: ' + position + ', start: ' + start + ', end: ' + end + ', token: ' + token); \t\t\t\treturn token; \t\t\t}, \t\t\tset: function(element, token) { \t\t\t\tvar text = element.get('value'); \t\t\t\tvar position = element.getCaretPosition(); \t\t\t\tvar start = text.lastIndexOf(' ', position - 1); \t\t\t\tvar end = text.indexOf(' ', position); \t\t\t\tif (start == -1) { \t\t\t\t\tstart = 0; \t\t\t\t} \t\t\t\telse { \t\t\t\t\tstart ++; \t\t\t\t} \t\t\t\tif (end == -1) { \t\t\t\t\tend = text.length; \t\t\t\t} \t\t\t\ttext = text.substring(0, start) + token + text.substring(end); \t\t\t\telement.set('value', text); \t\t\t\telement.setCaretPosition(start + token.length); \t\t\t} \t\t} \t}; \tnew Meio.Autocomplete(element, tokens, options); } </script> EOF; $injected = true; } }
/** * {@inheritdoc} */ public function handleEvent(ActionEvent $event) { $this->setEnvironment($event->getEnvironment()); parent::handleEvent($event); }
/** * @param ActionEvent $event * * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function handleActionForSelectri(ActionEvent $event) { if (!\Input::get('striAction') || !\Input::get('striID') || \Input::get('striID') === '' && \Input::get('striAction') != 'levels') { return; } $environment = $event->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); $inputProvider = $environment->getInputProvider(); $providerInformation = $dataDefinition->getDataProviderDefinition()->getInformation($dataDefinition->getName()); $dataProviderClass = $providerInformation->getClassName(); /** @var EntityDataProvider $dataProvider */ $dataProvider = new $dataProviderClass(); $dataProvider->setBaseConfig(array('source' => $dataDefinition->getName())); $repository = $dataProvider->getEntityRepository(); $messageContent = null; if ($inputProvider->hasParameter('id')) { $modelId = ModelId::fromSerialized(\Input::get('id')); $messageContent = $repository->find($modelId->getId()); } if (!$messageContent) { $contentModel = $dataProvider->getEmptyModel(); foreach (array_keys($contentModel->getPropertiesAsArray()) as $property) { if (!$inputProvider->hasValue($property)) { continue; } $contentModel->setProperty($property, $inputProvider->getValue($property)); } $messageContent = $contentModel->getEntity(); } $model = new EntityModel($messageContent); $selectriProperty = null; foreach ($dataDefinition->getPalettesDefinition()->getPalettes() as $palette) { foreach ($palette->getLegends() as $legend) { foreach ($legend->getProperties() as $legendProperty) { $property = $dataDefinition->getPropertiesDefinition()->getProperty($legendProperty->getName()); if (!in_array($property->getWidgetType(), array('selectri', 'avisotaSelectriWithItems')) || $legendProperty->getName() != \Input::get('striID')) { continue; } $model->getEntity()->setType($palette->getName()); $selectriProperty = $property; } } } if (!$selectriProperty) { return; } $widgetManager = new ContaoWidgetManager($environment, $model); $widgetManager->renderWidget($selectriProperty->getName()); }
public function handleAction(ActionEvent $event) { $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalDriver.css'; if ($event->getEnvironment()->getDataDefinition()->getName() !== $this->environment->getDataDefinition()->getName() || $event->getResponse() !== null) { return; } $action = $event->getAction(); $name = $action->getName(); switch ($name) { case 'copy': case 'copyAll': case 'create': case 'cut': case 'cutAll': case 'paste': case 'delete': case 'move': case 'undo': case 'edit': case 'show': case 'showAll': case 'toggle': $response = call_user_func_array(array($this, $name), $action->getArguments()); $event->setResponse($response); break; default: } if ($this->getViewSection()->getModelCommands()->hasCommandNamed($name)) { $command = $this->getViewSection()->getModelCommands()->getCommandNamed($name); if ($command instanceof ToggleCommandInterface) { $this->toggle($name); } } }
/** * 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); }
/** * @param ActionEvent $event */ public function handleAction(ActionEvent $event) { if (!$event->getResponse() && $event->getEnvironment()->getDataDefinition()->getName() == 'orm_avisota_message' && $event->getAction()->getName() == 'preview') { $event->setResponse($this->renderPreviewView($event->getEnvironment())); } }
/** * Handle action events. * * @param ActionEvent $event The action event. * * @return void */ public function handleAction(ActionEvent $event) { $this->checkLanguage($event->getEnvironment()); }
/** * Handle the action event. * * @param ActionEvent $event The event to handle. * * @return void * * @throws \RuntimeException When the MetaModel could not be determined. */ public function handleActionEvent(ActionEvent $event) { $environment = $event->getEnvironment(); if ($environment->getDataDefinition()->getName() !== static::$table) { return; } if ($event->getAction()->getName() !== static::$actionName) { return; } $this->input = $environment->getInputProvider(); $referrer = new GetReferrerEvent(true, static::$table); $this->dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer); $this->environment = $environment; $this->translator = $environment->getTranslator(); $pid = ModelId::fromSerialized($this->input->getParameter('pid'))->getId(); $this->metaModel = $this->getMetaModelById($this->database->prepare('SELECT * FROM ' . static::$ptable . ' WHERE id=?')->execute($pid)->pid); if (!$this->metaModel) { throw new \RuntimeException('Could not retrieve MetaModel from ' . $this->input->getParameter('pid')); } $startSort = 0; $this->knownAttributes = array(); $alreadyExisting = $this->database->prepare('SELECT * FROM ' . static::$table . ' WHERE pid=? ORDER BY sorting ASC')->execute($pid); while ($alreadyExisting->next()) { $this->knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row(); // Keep the sorting value. $startSort = $alreadyExisting->sorting; } if ($this->input->hasValue('add') || $this->input->hasValue('saveNclose')) { $this->perform($startSort + 128, $pid); } if ($this->input->hasValue('saveNclose')) { \Controller::redirect($referrer->getReferrerUrl()); } $this->template = new \BackendTemplate('be_addallattributes'); $this->template->href = $referrer->getReferrerUrl(); $this->template->backBt = $this->translator->translate('MSC.backBT'); $this->template->add = $this->translator->translate('MSC.continue'); $this->template->saveNclose = $this->translator->translate('MSC.saveNclose'); $this->template->headline = $this->translator->translate('addall.1', static::$table); $this->template->selectAll = $this->translator->translate('MSC.selectAll'); $this->template->cacheMessage = ''; $this->template->updateMessage = ''; $this->template->hasCheckbox = false; $this->template->fields = $this->generateForm(); $event->setResponse($this->template->parse()); }
/** * Handle copy each children. * * @param ActionEvent $event The event. * @param string $name The event name. * @param EventDispatcher $eventDispatcher The event dispatcher. * * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function handleCopyChilds(ActionEvent $event, $name, EventDispatcher $eventDispatcher) { if ($event->getAction()->getName() !== 'copyChilds' || !\Input::get('ctable')) { return; } $environment = $event->getEnvironment(); $inputProvider = $environment->getInputProvider(); $modelId = ModelId::fromSerialized($inputProvider->getParameter('id')); if ($environment->getDataDefinition()->getName() !== $inputProvider->getParameter('ctable') && $environment->getParentDataDefinition()->getName() !== $modelId->getDataProviderName()) { $this->redirectToChildTable($environment); } $copiedParentModel = $this->copyParent($modelId, $environment); $this->copyEachChilds($modelId, $copiedParentModel, $environment); $this->redirectToChildTable($environment, true); }