*/ protected array $attributes = []; /** * Whether this item is currently active/selected */ protected bool $active = false; public function setTag(string $tag): static { $this->tag = htmlspecialchars(trim($tag)); return $this; } public function getTag(): string { return $this->tag; } public function getIcon(): ?Icon { return $this->icon; } public function setIcon(?Icon $icon): static { $icon?->setSize(IconSize::SMALL); $this->icon = $icon; return $this; } public function getLabel(): ?string { return $this->label; } public function setLabel(?string $label): static { $this->label = $label; return $this; } public function getTitle(): ?string { return $this->title ?? $this->label; } public function setTitle(?string $title): static { $this->title = $title; return $this; } public function getHref(): ?string { return $this->href; } public function setHref(?string $href): static { $this->href = $href; return $this; } /** * @param array $attributes */ public function setAttributes(array $attributes): static { $this->attributes = $attributes; return $this; } public function setAttribute(string $name, string $value): static { $this->attributes[$name] = $value; return $this; } /** * @return array */ public function getAttributes(): array { return $this->attributes; } public function isActive(): bool { return $this->active; } public function setActive(bool $active): static { $this->active = $active; return $this; } public function isValid(): bool { return $this->getLabel() !== null && trim($this->getLabel()) !== ''; } public function getType(): string { return static::class; } protected function getAttributesString(): string { $attributes = $this->getAttributes(); $attributes['class'] = rtrim('dropdown-item dropdown-item-spaced ' . ($attributes['class'] ?? '')); if ($this->isActive()) { $attributes['aria-selected'] = 'true'; } if ($this->getHref()) { $attributes['href'] = $this->getHref(); } if ($this->getTitle()) { $attributes['title'] = $this->getTitle(); } return GeneralUtility::implodeAttributes($attributes, true); } protected function getRenderedIcon(): string { return $this->getIcon()?->render() ?? ''; } abstract public function render(): string; public function __toString(): string { return $this->render(); } }