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