/** * Update the event with the information returned by the callback. * * @param GetGlobalButtonEvent $event The event being emitted. * * @param string $value The HTML representation of the button. * * @return void */ public function update($event, $value) { if ($value === null) { return; } $event->setHtml($value); $event->stopPropagation(); }
/** * Clear the button if the User is not admin. * * @param GetGlobalButtonEvent $event The event. * * @return void */ public function getGlobalButton(GetGlobalButtonEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') { return; } // FIXME: direct access to BackendUser. if (!\BackendUser::getInstance()->isAdmin) { $event->setHtml(''); } }
/** * Check the permission for send or preview message button. * * @param GetGlobalButtonEvent $event The event. * * @return void */ public function checkPermissionSendMessageButton(GetGlobalButtonEvent $event) { $environment = $event->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); if ($dataDefinition->getName() !== 'orm_avisota_message_content' || $event->getKey() !== 'send') { return; } $user = BackendUser::getInstance(); if (!$user->isAdmin || !$user->hasAccess('send', 'avisota_newsletter_permission')) { $event->setHtml(''); } }
/** * Render a single header button. * * @param CommandInterface $command The command definition. * * @return string */ protected function generateHeaderButton(CommandInterface $command) { $environment = $this->getEnvironment(); $extra = $command->getExtra(); $label = $this->translate($command->getLabel()); $dispatcher = $environment->getEventDispatcher(); if (isset($extra['href'])) { $href = $extra['href']; } else { $href = ''; foreach ($command->getParameters() as $key => $value) { $href .= '&' . $key . '=' . $value; } /** @var AddToUrlEvent $event */ $event = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($href)); $href = $event->getUrl(); } if (!strlen($label)) { $label = $command->getName(); } $buttonEvent = new GetGlobalButtonEvent($this->getEnvironment()); $buttonEvent->setAccessKey(isset($extra['accesskey']) ? trim($extra['accesskey']) : null)->setAttributes(' ' . ltrim($extra['attributes']))->setClass($extra['class'])->setKey($command->getName())->setHref($href)->setLabel($label)->setTitle($this->translate($command->getDescription())); $environment->getEventDispatcher()->dispatch(GetGlobalButtonEvent::NAME, $buttonEvent); // Allow to override the button entirely. $html = $buttonEvent->getHtml(); if ($html !== null) { return $html; } // Use the view native button building. return sprintf('<a href="%s" class="%s" title="%s"%s>%s</a> ', $buttonEvent->getHref(), $buttonEvent->getClass(), specialchars($buttonEvent->getTitle()), $buttonEvent->getAttributes(), $buttonEvent->getLabel()); }