* {f:translate(id: button.title, default: button.title)} * */ final class ButtonViewHelper extends AbstractTagBasedViewHelper { /** * @var string */ protected $tagName = 'a'; public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('button', ButtonProviderInterface::class, 'Dashboard widget button', true); } public function render(): string { $button = $this->arguments['button']; $this->tag->addAttribute('href', $button->getLink() ?: '#'); $target = $button->getTarget(); if ($target !== '') { $this->tag->addAttribute('target', $target); if ($target === '_blank') { $this->tag->addAttribute('rel', 'noreferrer'); } } if ($button instanceof ElementAttributesInterface) { $this->tag->addAttributes($button->getElementAttributes()); } $this->tag->setContent((string)$this->renderChildren()); $this->tag->forceClosingTag(true); return $this->tag->render(); } }