TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconSize;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Base class for all dropdown menu items that can be added to DropDownButton or SplitButton.
|
||||
* Provides common functionality for dropdown items including icon handling, labels, links,
|
||||
* custom HTML tags, and active state management.
|
||||
*
|
||||
* Implements DropDownItemInterface, providing validation, type identification, and rendering
|
||||
* capabilities for all dropdown items.
|
||||
*/
|
||||
abstract class AbstractDropDownItem implements \Stringable
|
||||
{
|
||||
/**
|
||||
* HTML tag name for the dropdown item element (e.g., 'a', 'button', custom elements)
|
||||
*/
|
||||
protected string $tag = 'a';
|
||||
|
||||
/**
|
||||
* Optional icon displayed before the label
|
||||
*/
|
||||
protected ?Icon $icon = null;
|
||||
|
||||
/**
|
||||
* Text content/label of the dropdown item
|
||||
*/
|
||||
protected ?string $label = null;
|
||||
|
||||
/**
|
||||
* Tooltip/title attribute (defaults to label if not explicitly set)
|
||||
*/
|
||||
protected ?string $title = null;
|
||||
|
||||
/**
|
||||
* URL/href for link items
|
||||
*/
|
||||
protected ?string $href = null;
|
||||
|
||||
/**
|
||||
* Custom HTML attributes for the element
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
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<string, string> $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<string, string>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
/**
|
||||
* This dropdown item type renders the divider element.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* $item = $this->componentFactory->createDropDownDivider()
|
||||
* $dropDownButton->addItem($item);
|
||||
* ```
|
||||
*/
|
||||
class DropDownDivider implements DropDownItemInterface
|
||||
{
|
||||
public function getType(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return '<hr class="dropdown-divider">';
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
/**
|
||||
* Dropdown item with relaxed validation - like DropDownItem but label is optional.
|
||||
*
|
||||
* Use for web components or custom elements that render their own content.
|
||||
*/
|
||||
class DropDownGeneric extends AbstractDropDownItem implements DropDownItemInterface
|
||||
{
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->tag !== '';
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return sprintf(
|
||||
'<%1$s %2$s>%3$s%4$s</%1$s>',
|
||||
$this->getTag(),
|
||||
$this->getAttributesString(),
|
||||
$this->getRenderedIcon(),
|
||||
htmlspecialchars($this->getLabel() ?? '')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
/**
|
||||
* This dropdown item type renders a noninteractive text element
|
||||
* to group items and gives more meaning to a set of options.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* $item = $this->componentFactory->createDropDownHeader()->setLabel('Label');
|
||||
* $dropDownButton->addItem($item);
|
||||
* ```
|
||||
*/
|
||||
class DropDownHeader implements DropDownItemInterface
|
||||
{
|
||||
protected ?string $label = null;
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(?string $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->getLabel() !== null && trim($this->getLabel()) !== '';
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return '<h6 class="dropdown-header">' . htmlspecialchars(trim($this->getLabel())) . '</h6>';
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
/**
|
||||
* This dropdown item type renders a simple element.
|
||||
* Use this element if you need a link, button.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* $item = $this->componentFactory->createDropDownItem()
|
||||
* ->setTag('a')
|
||||
* ->setHref('#')
|
||||
* ->setLabel('Label')
|
||||
* ->setTitle('Title')
|
||||
* ->setIcon($this->iconFactory->getIcon('actions-heart'))
|
||||
* ->setAttributes(['data-value' => '123']);
|
||||
* $dropDownButton->addItem($item);
|
||||
* ```
|
||||
*/
|
||||
class DropDownItem extends AbstractDropDownItem implements DropDownItemInterface
|
||||
{
|
||||
public function render(): string
|
||||
{
|
||||
return sprintf(
|
||||
'<%1$s %2$s>%3$s%4$s</%1$s>',
|
||||
$this->getTag(),
|
||||
$this->getAttributesString(),
|
||||
$this->getIcon()?->render() ?? '',
|
||||
htmlspecialchars($this->getLabel())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
use TYPO3\CMS\Backend\Template\Components\ComponentInterface;
|
||||
|
||||
/**
|
||||
* Interface for dropdown items that can be added to a DropDownButton.
|
||||
*
|
||||
* Dropdown items include interactive elements (DropDownItem, DropDownRadio, DropDownToggle)
|
||||
* and structural elements (DropDownHeader, DropDownDivider).
|
||||
*
|
||||
* This interface extends ComponentInterface, which provides the common contract
|
||||
* for all renderable backend components.
|
||||
*/
|
||||
interface DropDownItemInterface extends ComponentInterface {}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Imaging\IconSize;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This dropdown item type renders an element with an active state.
|
||||
* Use this element to display a radio-like selection of a state.
|
||||
* When set to active, it will show a dot in front of the icon and
|
||||
* text to indicate that this is the current selection.
|
||||
*
|
||||
* At least 2 of these items need to exist within a dropdown button,
|
||||
* so a user has a choice of a state to select.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* $item = $this->componentFactory->createDropDownRadio()
|
||||
* ->setHref('#')
|
||||
* ->setActive(true)
|
||||
* ->setLabel('List')
|
||||
* ->setTitle('List')
|
||||
* ->setIcon($this->iconFactory->getIcon('actions-viewmode-list'))
|
||||
* ->setAttributes(['data-type' => 'list']);
|
||||
* $dropDownButton->addItem($item);
|
||||
*
|
||||
* $item = $this->componentFactory->createDropDownRadio()
|
||||
* ->setHref('#')
|
||||
* ->setActive(false)
|
||||
* ->setLabel('Tiles')
|
||||
* ->setTitle('Tiles')
|
||||
* ->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles'))
|
||||
* ->setAttributes(['data-type' => 'tiles']);
|
||||
* $dropDownButton->addItem($item);
|
||||
* ```
|
||||
*/
|
||||
class DropDownRadio extends AbstractDropDownItem implements DropDownItemInterface
|
||||
{
|
||||
public function render(): string
|
||||
{
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
$statusIcon = $this->isActive()
|
||||
? '<span class="text-primary">' . $iconFactory->getIcon('actions-dot', IconSize::SMALL)->render() . '</span>'
|
||||
: $iconFactory->getIcon('empty-empty', IconSize::SMALL)->render();
|
||||
|
||||
return sprintf(
|
||||
'<%1$s %2$s>%3$s%4$s%5$s</%1$s>',
|
||||
$this->getTag(),
|
||||
$this->getAttributesString(),
|
||||
$statusIcon,
|
||||
$this->getRenderedIcon(),
|
||||
htmlspecialchars($this->getLabel())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Template\Components\Buttons\DropDown;
|
||||
|
||||
/**
|
||||
* This dropdown item type renders an element with an active state.
|
||||
* When set to active, it will show a checkmark in front of the icon
|
||||
* and text to indicate the current state.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* $item = $this->componentFactory->createDropDownToggle()
|
||||
* ->setHref('#')
|
||||
* ->setActive(true)
|
||||
* ->setLabel('Label')
|
||||
* ->setTitle('Title')
|
||||
* ->setIcon($this->iconFactory->getIcon('actions-heart'))
|
||||
* ->setAttributes(['data-value' => '123']);
|
||||
* $dropDownButton->addItem($item);
|
||||
* ```
|
||||
*/
|
||||
class DropDownToggle extends AbstractDropDownItem implements DropDownItemInterface
|
||||
{
|
||||
public function render(): string
|
||||
{
|
||||
// Status Icon
|
||||
$this->setAttribute('data-dropdowntoggle-status', $this->isActive() ? 'active' : 'inactive');
|
||||
return sprintf(
|
||||
'<%1$s %2$s><span class="dropdown-item-status"></span>%3$s%4$s</%1$s>',
|
||||
$this->getTag(),
|
||||
$this->getAttributesString(),
|
||||
$this->getRenderedIcon(),
|
||||
htmlspecialchars($this->getLabel())
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user