‪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 
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 
104  public function ‪isValid(): bool
105  {
106  return $this->‪getLabel() !== null && trim($this->‪getLabel()) !== '';
107  }
108 
109  public function ‪getType(): string
110  {
111  return static::class;
112  }
113 
114  protected function ‪getAttributesString(): string
115  {
116  ‪$attributes = $this->getAttributes();
117  ‪$attributes['class'] = 'dropdown-item dropdown-item-spaced';
118  if ($this->‪getHref()) {
119  $attributes['href'] = $this->‪getHref();
120  }
121  if ($this->‪getTitle()) {
122  $attributes['title'] = $this->‪getTitle();
123  }
124 
125  return GeneralUtility::implodeAttributes(‪$attributes, true);
126  }
127 
128  protected function ‪getRenderedIcon(): string
129  {
130  return $this->‪getIcon()?->render() ?? '';
131  }
132 
133  abstract public function ‪render();
134 
135  public function ‪__toString(): string
136  {
137  return $this->‪render();
138  }
139 }
‪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:135
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\isValid
‪isValid()
Definition: AbstractDropDownItem.php:104
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\getAttributesString
‪getAttributesString()
Definition: AbstractDropDownItem.php:114
‪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:128
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\AbstractDropDownItem\setTitle
‪setTitle(?string $title)
Definition: AbstractDropDownItem.php:70
‪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:109
‪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