moduleTemplate->getDocHeaderComponent()->getButtonBar(); * $saveButton = $this->componentFactory->createLinkButton() * ->setHref('#') * ->setDataAttributes([ * 'foo' => 'bar' * ]) * ->setIcon($this->iconFactory->getIcon('actions-document-save', IconSize::SMALL)) * ->setTitle('Save'); * $buttonBar->addButton($saveButton, ButtonBar::BUTTON_POSITION_LEFT, 1); * } * ``` */ class LinkButton extends AbstractButton { protected string $href = ''; protected string $role = 'button'; protected ButtonSize $size = ButtonSize::SMALL; public function getHref(): string { return $this->href; } public function setHref(string $href): static { $this->href = $href; return $this; } public function getRole(): string { return $this->role; } public function setRole(string $role): static { $this->role = $role; return $this; } public function getSize(): ButtonSize { return $this->size; } public function setSize(ButtonSize $size): static { $this->size = $size; return $this; } public function isValid(): bool { return trim($this->getHref()) !== '' && trim($this->getTitle()) !== '' && $this->getType() === static::class && $this->getIcon() !== null; } public function render(): string { $attributes = [ 'role' => $this->getRole(), 'href' => $this->getHref(), // @see SplitButton - hard-coded replacement for this hard-coded class-list 'class' => 'btn ' . $this->getSize()->value . ' btn-default ' . $this->getClasses(), 'title' => $this->getTitle(), ]; $labelText = ''; if ($this->showLabelText) { $labelText = ' ' . $this->title; } foreach ($this->attributes as $attributeName => $attributeValue) { $attributes[$attributeName] = $attributeValue; } foreach ($this->dataAttributes as $attributeName => $attributeValue) { $attributes['data-' . $attributeName] = $attributeValue; } if ($this->isDisabled()) { $attributes['aria-disabled'] = 'true'; $attributes['class'] .= ' disabled'; } return sprintf( '%s%s', GeneralUtility::implodeAttributes($attributes, true), $this->getIcon()?->render() ?? '', htmlspecialchars($labelText), ); } public function __toString(): string { return $this->render(); } }