‪TYPO3CMS  ‪main
AbstractDropDownItem.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\CMS\Core\Imaging\IconSize;
21 
22 abstract class ‪AbstractDropDownItem implements \Stringable
23 {
24  protected string ‪$tag = 'a';
25  protected ?‪Icon ‪$icon = null;
26  protected ?string ‪$label = null;
27  protected ?string ‪$title = null;
28  protected ?string ‪$href = null;
29  protected array ‪$attributes = [];
30  protected bool ‪$active = false;
31  public function ‪setTag(string ‪$tag): self
32  {
33  $this->$tag = htmlspecialchars(trim(‪$tag));
34  return $this;
35  }
36 
37  public function ‪getTag(): string
38  {
39  return ‪$this->tag;
40  }
41 
42  public function ‪getIcon(): ?‪Icon
43  {
44  return ‪$this->icon;
45  }
46 
47  public function ‪setIcon(?‪Icon ‪$icon): self
48  {
49  ‪$icon?->‪setSize(IconSize::SMALL);
50  $this->icon = ‪$icon;
51  return $this;
52  }
53 
54  public function ‪getLabel(): ?string
55  {
56  return ‪$this->label;
57  }
58 
59  public function ‪setLabel(?string ‪$label): self
60  {
61  $this->label = ‪$label;
62  return $this;
63  }
64 
65  public function ‪getTitle(): ?string
66  {
67  return $this->title ?? ‪$this->label;
68  }
69 
70  public function ‪setTitle(?string ‪$title): self
71  {
72  $this->title = ‪$title;
73  return $this;
74  }
75 
76  public function ‪getHref(): ?string
77  {
78  return ‪$this->href;
79  }
80 
81  public function ‪setHref(?string ‪$href): self
82  {
83  $this->href = ‪$href;
84  return $this;
85  }
86 
90  public function ‪setAttributes(array ‪$attributes): self
91  {
93  return $this;
94  }
95 
99  public function getAttributes(): array
100  {
102  }
103  public function ‪isActive(): bool
104  {
105  return ‪$this->active;
106  }
107 
108  public function ‪setActive(bool ‪$active): self
109  {
110  $this->active = ‪$active;
111  return $this;
112  }
113 
114  public function ‪isValid(): bool
115  {
116  return $this->‪getLabel() !== null && trim($this->‪getLabel()) !== '';
117  }
118 
119  public function ‪getType(): string
120  {
121  return static::class;
122  }
123 
124  protected function ‪getAttributesString(): string
125  {
126  ‪$attributes = $this->getAttributes();
127  ‪$attributes['class'] = 'dropdown-item dropdown-item-spaced';
128  if ($this->‪isActive()) {
129  $attributes['aria-selected'] = 'true';
130  }
131  if ($this->‪getHref()) {
132  $attributes['href'] = $this->‪getHref();
133  }
134  if ($this->‪getTitle()) {
135  $attributes['title'] = $this->‪getTitle();
136  }
137 
138  return GeneralUtility::implodeAttributes(‪$attributes, true);
139  }
140 
141  protected function ‪getRenderedIcon(): string
142  {
143  return $this->‪getIcon()?->render() ?? '';
144  }
145 
146  abstract public function ‪render();
147 
148  public function ‪__toString(): string
149  {
150  return $this->‪render();
151  }
152 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$active
‪bool $active
Definition: AbstractDropDownItem.php:30
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem
Definition: AbstractDropDownItem.php:23
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$icon
‪Icon $icon
Definition: AbstractDropDownItem.php:25
‪TYPO3\CMS\Core\Imaging\Icon\setSize
‪setSize(string|IconSize $size)
Definition: Icon.php:193
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setIcon
‪setIcon(?Icon $icon)
Definition: AbstractDropDownItem.php:47
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getTitle
‪getTitle()
Definition: AbstractDropDownItem.php:65
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getTag
‪getTag()
Definition: AbstractDropDownItem.php:37
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$tag
‪string $tag
Definition: AbstractDropDownItem.php:24
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\attributes
‪array< string, function getAttributes():array { return $this-> attributes
Definition: AbstractDropDownItem.php:101
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getHref
‪getHref()
Definition: AbstractDropDownItem.php:76
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\__toString
‪__toString()
Definition: AbstractDropDownItem.php:148
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setActive
‪setActive(bool $active)
Definition: AbstractDropDownItem.php:108
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\isValid
‪isValid()
Definition: AbstractDropDownItem.php:114
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getAttributesString
‪getAttributesString()
Definition: AbstractDropDownItem.php:124
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setTag
‪setTag(string $tag)
Definition: AbstractDropDownItem.php:31
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown
Definition: AbstractDropDownItem.php:16
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\render
‪render()
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setHref
‪setHref(?string $href)
Definition: AbstractDropDownItem.php:81
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$label
‪string $label
Definition: AbstractDropDownItem.php:26
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$href
‪string $href
Definition: AbstractDropDownItem.php:28
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getLabel
‪getLabel()
Definition: AbstractDropDownItem.php:54
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$title
‪string $title
Definition: AbstractDropDownItem.php:27
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getRenderedIcon
‪getRenderedIcon()
Definition: AbstractDropDownItem.php:141
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setTitle
‪setTitle(?string $title)
Definition: AbstractDropDownItem.php:70
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\isActive
‪isActive()
Definition: AbstractDropDownItem.php:103
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setLabel
‪setLabel(?string $label)
Definition: AbstractDropDownItem.php:59
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getType
‪getType()
Definition: AbstractDropDownItem.php:119
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getIcon
‪getIcon()
Definition: AbstractDropDownItem.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\$attributes
‪array $attributes
Definition: AbstractDropDownItem.php:29
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setAttributes
‪setAttributes(array $attributes)
Definition: AbstractDropDownItem.php:90