/** * @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(); } }
/** * 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()); }
/** * @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 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()); }
/** * 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()); }
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); } }
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); } } }