Adding button to Widget¶
In order to add a button to a widget, a new dependency to an Button
can be added.
Template¶
The output itself is done inside of the Fluid template, for example Resources/
:
<f:if condition="{button}">
<a href="{button.link}" target="{button.target}" class="widget-cta">
{f:translate(id: button.title, default: button.title)}
</a>
</f:if>
Configuration¶
The configuration is done through an configured Instance of the dependency, for example Services.
:
services:
# …
dashboard.buttons.t3news:
class: 'TYPO3\CMS\Dashboard\Widgets\Provider\ButtonProvider'
arguments:
$title: 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.moreItems'
$link: 'https://typo3.org/project/news'
$target: '_blank'
dashboard.widget.t3news:
class: 'TYPO3\CMS\Dashboard\Widgets\RssWidget'
arguments:
# …
$buttonProvider: '@dashboard.buttons.t3news'
# …
See also: \TYPO3\
.
-
- Type
- string
The title used for the button. E.g. an
LLL:EXT:
reference likeLLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.moreItems
.
-
- Type
- string
The link to use for the button. Clicking the button will open the link.
-
- Type
- string
The target of the link, e.g.
_blank
.LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.moreItems
.
Implementation¶
An example implementation could look like this:
class RssWidget implements WidgetInterface
{
public function __construct(
// …
private readonly ButtonProviderInterface $buttonProvider = null,
// …
) {
}
public function renderWidgetContent(): string
{
// …
$this->view->assignMultiple([
// …
'button' => $this->buttonProvider,
// …
]);
// …
}
public function getOptions(): array
{
return $this->options;
}
}