/** * Set the value in the event. * * @param GetOperationButtonEvent $event The event being emitted. * * @param string $value The value returned by the callback. * * @return void */ public function update($event, $value) { if (is_null($value)) { return; } $event->setHtml($value); $event->stopPropagation(); }
/** * Check if we have to add the "Create variant" button. * * @param GetOperationButtonEvent $event The event. * * @return void */ public function createButton(GetOperationButtonEvent $event) { if ($event->getCommand()->getName() != 'createvariant') { return; } /** @var Model $model */ $model = $event->getModel(); $metamodel = $model->getItem()->getMetaModel(); if (!$metamodel->hasVariants() || $model->getProperty('varbase') === '0') { $event->setHtml(''); } }
/** * Clear the button if the User is not admin. * * @param GetOperationButtonEvent $event The event. * * @return void */ public function getOperationButton(GetOperationButtonEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') { return; } $command = $event->getCommand(); if ($command->getName() == 'dca_combine') { $event->setHref(UrlBuilder::fromUrl($event->getHref())->setQueryParameter('id', ModelId::fromValues('tl_metamodel_dca_combine', $event->getModel()->getId())->getSerialized())->getUrl()); } }
/** * Render a command button. * * @param CommandInterface $command The command to render the button for. * * @param ModelInterface $model The model to which the command shall get applied. * * @param ModelInterface $previous The previous model in the collection. * * @param ModelInterface $next The next model in the collection. * * @param bool $isCircularReference Determinator if there exists a circular reference between the model * and the model(s) contained in the clipboard. * * @param string[] $childIds The ids of all child models. * * @return string */ private function buildCommand($command, $model, $previous, $next, $isCircularReference, $childIds) { $extra = (array) $command->getExtra(); $attributes = ''; if (!empty($extra['attributes'])) { $attributes .= sprintf($extra['attributes'], $model->getID()); } $label = $this->getCommandLabel($command); $title = sprintf($this->translate($command->getDescription()), $model->getID()); $icon = $extra['icon']; if ($command instanceof ToggleCommandInterface) { $iconDisabled = isset($extra['icon_disabled']) ? $extra['icon_disabled'] : 'invisible.gif'; $attributes .= sprintf(' onclick="Backend.getScrollOffset(); return BackendGeneral.toggleVisibility(this, \'%s\', \'%s\');"', $icon, $iconDisabled); if (!$this->isTogglerInActiveState($command, $model)) { $icon = $iconDisabled; } } $href = $this->calculateHref($command, $model); $buttonEvent = new GetOperationButtonEvent($this->environment); $buttonEvent->setCommand($command)->setObjModel($model)->setAttributes($attributes)->setLabel($label)->setTitle($title)->setHref($href)->setChildRecordIds($childIds)->setCircularReference($isCircularReference)->setPrevious($previous)->setNext($next)->setDisabled($command->isDisabled()); $this->eventDispatcher->dispatch(GetOperationButtonEvent::NAME, $buttonEvent); if (null !== ($html = $buttonEvent->getHtml())) { // If the event created a button, use it. return trim($html); } if ($buttonEvent->isDisabled()) { return $this->renderImageAsHtml(substr_replace($icon, '_1', strrpos($icon, '.'), 0), $buttonEvent->getLabel()); } return sprintf(' <a href="%s" title="%s" %s>%s</a>', $buttonEvent->getHref(), specialchars($buttonEvent->getTitle()), ltrim($buttonEvent->getAttributes()), $this->renderImageAsHtml($icon, $buttonEvent->getLabel())); }
/** * @param GetOperationButtonEvent $event */ public function prepareButton(GetOperationButtonEvent $event) { if ($event->getCommand()->getName() != 'ga_enabled') { return; } /** @var \Pimple $container */ global $container; /** @var SuperglobalsService $superGlobals */ $superGlobals = $container['avisota.superglobals']; /** @var EntityModel $model */ $model = $event->getModel(); /** @var Message $message */ $message = $model->getEntity(); if ($message->getGaEnable()) { $title = $message->getGaCampaign() ? $message->getGaCampaign() : $message->getSubject(); $title = sprintf($superGlobals->getLanguage('orm_avisota_message/ga_campain_title'), $title); $generateHtmlEvent = new GenerateHtmlEvent('assets/avisota/message-analytics-ga/images/analytics_icon.png', $title, sprintf('title="%s"', htmlentities($title, ENT_QUOTES, 'UTF-8'))); $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, $generateHtmlEvent); $event->setHtml($generateHtmlEvent->getHtml()); } else { $event->setHtml(''); } }
/** * Check if the Layouts by this theme is in used by message. * If layout in used, return where and can´t delete the theme. * * @param GetOperationButtonEvent $event The event. * * @return void */ public function deleteInformation(GetOperationButtonEvent $event) { $command = $event->getCommand(); $environment = $event->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); if ($dataDefinition->getName() !== 'orm_avisota_theme' || $command->getName() !== 'delete') { return; } $themeEntity = $event->getModel()->getEntity(); $layoutCollection = $themeEntity->getLayouts(); $information = ''; while ($layoutEntity = $layoutCollection->current()) { $currentInformation = $this->getLayoutUsedInformation($layoutEntity, $environment); if (!$currentInformation) { $layoutCollection->next(); continue; } $information .= $currentInformation; $layoutCollection->next(); } if (!$information) { return; } $translator = $environment->getTranslator(); $information = $translator->translate('delete.information.theme', 'MCE') . $information; $event->setAttributes('onclick="alert(\'' . $information . '\'); Backend.getScrollOffset(); return false;"'); }
/** * Render a command button. * * @param CommandInterface $objCommand The command to render the button for. * * @param ModelInterface $objModel The model to which the command shall get applied. * * @param bool $blnCircularReference Determinator if there exists a circular reference between the model * and the model(s) contained in the clipboard. * * @param array $arrChildRecordIds List of the ids of all child models of the current model. * * @param ModelInterface $previous The previous model in the collection. * * @param ModelInterface $next The next model in the collection. * * @return string */ protected function buildCommand($objCommand, $objModel, $blnCircularReference, $arrChildRecordIds, $previous, $next) { $environment = $this->getEnvironment(); $inputProvider = $environment->getInputProvider(); $dispatcher = $environment->getEventDispatcher(); $dataDefinitionName = $environment->getDataDefinition()->getName(); $commandName = $objCommand->getName(); $parameters = (array) $objCommand->getParameters(); $extra = (array) $objCommand->getExtra(); $extraAttributes = !empty($extra['attributes']) ? $extra['attributes'] : null; $attributes = ''; // Set basic information. $opLabel = $objCommand->getLabel(); if (strlen($opLabel)) { $label = $opLabel; } else { $label = $commandName; } $label = $this->translate($label, $dataDefinitionName); if (is_array($label)) { $label = $label[0]; } $opDesc = $this->translate($objCommand->getDescription(), $dataDefinitionName); if (strlen($opDesc)) { $title = sprintf($opDesc, $objModel->getID()); } else { $title = sprintf('%s id %s', $label, $objModel->getID()); } // Toggle has to trigger the javascript. if ($objCommand instanceof ToggleCommandInterface) { $parameters['act'] = $commandName; $icon = $extra['icon']; $iconDisabled = isset($extra['icon_disabled']) ? $extra['icon_disabled'] : 'invisible.gif'; $attributes = sprintf('onclick="Backend.getScrollOffset(); return BackendGeneral.toggleVisibility(this, \'%s\', \'%s\');"', $icon, $iconDisabled); $dataProvider = $this->getEnvironment()->getDataProvider($objModel->getProviderName()); if ($objCommand instanceof TranslatedToggleCommandInterface && $dataProvider instanceof MultiLanguageDataProviderInterface) { $language = $dataProvider->getCurrentLanguage(); $dataProvider->setCurrentLanguage($objCommand->getLanguage()); $propModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($objModel->getId())->setFields($objCommand->getToggleProperty())); $dataProvider->setCurrentLanguage($language); } else { $propModel = $objModel; } $state = $objCommand->isInverse() ? !$propModel->getProperty($objCommand->getToggleProperty()) : $propModel->getProperty($objCommand->getToggleProperty()); if (!$state) { $extra['icon'] = $iconDisabled ?: 'invisible.gif'; } } if ($extraAttributes) { $attributes .= ltrim(sprintf($extraAttributes, $objModel->getID())); } $serializedModelId = ModelId::fromModel($objModel)->getSerialized(); // Cut needs some special information. if ($objCommand instanceof CutCommandInterface) { $parameters = array(); $parameters['act'] = $commandName; // If we have a pid add it, used for mode 4 and all parent -> current views. if ($inputProvider->hasParameter('pid')) { $parameters['pid'] = $inputProvider->getParameter('pid'); } // Source is the id of the element which should move. $parameters['source'] = $serializedModelId; } elseif ($objCommand instanceof CopyCommandInterface) { // The copy operation. $parameters = array(); $parameters['act'] = $commandName; // If we have a pid add it, used for mode 4 and all parent -> current views. if ($inputProvider->hasParameter('pid')) { $parameters['pid'] = $inputProvider->getParameter('pid'); } // Source is the id of the element which should move. $parameters['source'] = $serializedModelId; } else { // TODO: Shall we interface this option? $idParam = isset($extra['idparam']) ? $extra['idparam'] : null; if ($idParam) { $parameters[$idParam] = $serializedModelId; } else { $parameters['id'] = $serializedModelId; } } $strHref = ''; foreach ($parameters as $key => $value) { $strHref .= sprintf('&%s=%s', $key, $value); } /** @var AddToUrlEvent $event */ $event = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($strHref)); $strHref = $event->getUrl(); $buttonEvent = new GetOperationButtonEvent($this->getEnvironment()); $buttonEvent->setCommand($objCommand)->setObjModel($objModel)->setAttributes($attributes)->setLabel($label)->setTitle($title)->setHref($strHref)->setChildRecordIds($arrChildRecordIds)->setCircularReference($blnCircularReference)->setPrevious($previous)->setNext($next)->setDisabled($objCommand->isDisabled()); $dispatcher->dispatch(GetOperationButtonEvent::NAME, $buttonEvent); // If the event created a button, use it. if ($buttonEvent->getHtml() !== null) { return trim($buttonEvent->getHtml()); } $icon = $extra['icon']; if ($buttonEvent->isDisabled()) { /** @var GenerateHtmlEvent $event */ $event = $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent(substr_replace($icon, '_1', strrpos($icon, '.'), 0), $buttonEvent->getLabel())); return $event->getHtml(); } /** @var GenerateHtmlEvent $event */ $event = $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent($icon, $buttonEvent->getLabel())); return sprintf(' <a href="%s" title="%s" %s>%s</a>', $buttonEvent->getHref(), specialchars($buttonEvent->getTitle()), $buttonEvent->getAttributes(), $event->getHtml()); }
/** * Check if the Layout is in used by message. * If this in used, return where and can´t delete it. * * @param GetOperationButtonEvent $event The event. * * @return void */ public function deleteInformation(GetOperationButtonEvent $event) { $command = $event->getCommand(); $environment = $event->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); if ($dataDefinition->getName() !== 'orm_avisota_layout' || $command->getName() !== 'delete') { return; } $entity = $event->getModel()->getEntity(); $dataProvider = $environment->getDataProvider(); $entityManager = $dataProvider->getEntityManager(); $repository = $entityManager->getRepository('Avisota\\Contao:Message'); $messageResult = $repository->findBy(array('layout' => $entity->getId()), array('subject' => 'ASC')); if (count($messageResult) < 1) { return; } $translator = $environment->getTranslator(); $information = $translator->translate('delete.information.layout', 'MCE'); foreach ($messageResult as $message) { $information .= "\\n"; $information .= $message->getCategory()->getTitle(); $information .= ' => '; $information .= $message->getSubject(); } $event->setAttributes('onclick="alert(\'' . $information . '\'); Backend.getScrollOffset(); return false;"'); }