-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractMenuButtonBuilder.php
More file actions
61 lines (52 loc) · 1.71 KB
/
AbstractMenuButtonBuilder.php
File metadata and controls
61 lines (52 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
/*
* This file is part of the "xima_typo3_frontend_edit" TYPO3 CMS extension.
*
* (c) 2024-2026 Konrad Michalik <hej@konradmichalik.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xima\XimaTypo3FrontendEdit\Service\Menu;
use TYPO3\CMS\Core\Localization\LanguageService;
use Xima\XimaTypo3FrontendEdit\Configuration;
use Xima\XimaTypo3FrontendEdit\Enumerations\ButtonType;
use Xima\XimaTypo3FrontendEdit\Service\Ui\{IconService, UrlBuilderService};
use Xima\XimaTypo3FrontendEdit\Template\Component\Button;
/**
* AbstractMenuButtonBuilder.
*
* @author Konrad Michalik <hej@konradmichalik.dev>
* @license GPL-2.0-or-later
*/
abstract readonly class AbstractMenuButtonBuilder
{
public function __construct(
protected IconService $iconService,
protected UrlBuilderService $urlBuilderService,
) {}
public function addButton(
Button $menuButton,
string $identifier,
ButtonType $type,
?string $label = null,
?string $url = null,
?string $icon = null,
): void {
$finalLabel = $label ?? 'LLL:EXT:'.Configuration::EXT_KEY."/Resources/Private/Language/locallang.xlf:$identifier";
$finalIcon = null !== $icon ? $this->iconService->getIcon($icon) : null;
$button = new Button(
$finalLabel,
$type,
$url,
$finalIcon,
false, // Target blank will be handled at a higher level
);
$menuButton->appendChild($button, $identifier);
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}