|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Template\Components\Menu\Menu; |
|
21
|
|
|
use TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper; |
|
22
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
23
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
24
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; |
|
25
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer; |
|
26
|
|
|
use TYPO3Fluid\Fluid\View\Exception; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* A ViewHelper for adding a menu item to a doc header menu. |
|
30
|
|
|
* It must be a child of :ref:`<be:moduleLayout.menu> <typo3-backend-modulelayout-menu>`. |
|
31
|
|
|
* |
|
32
|
|
|
* Examples |
|
33
|
|
|
* ======== |
|
34
|
|
|
* |
|
35
|
|
|
* Default:: |
|
36
|
|
|
* |
|
37
|
|
|
* <be:moduleLayout> |
|
38
|
|
|
* <be:moduleLayout.menu identifier="MenuIdentifier"> |
|
39
|
|
|
* <be:moduleLayout.menuItem label="Menu item 1" uri="{f:uri.action(action: 'index')}"/> |
|
40
|
|
|
* </be:moduleLayout.menu> |
|
41
|
|
|
* </be:moduleLayout> |
|
42
|
|
|
* |
|
43
|
|
|
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0. |
|
44
|
|
|
*/ |
|
45
|
|
|
class MenuItemViewHelper extends AbstractViewHelper |
|
46
|
|
|
{ |
|
47
|
|
|
use CompileWithRenderStatic; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Initialize arguments. |
|
51
|
|
|
* |
|
52
|
|
|
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception |
|
53
|
|
|
*/ |
|
54
|
|
|
public function initializeArguments() |
|
55
|
|
|
{ |
|
56
|
|
|
parent::initializeArguments(); |
|
57
|
|
|
$this->registerArgument('label', 'string', 'Label of the menu item', true); |
|
58
|
|
|
$this->registerArgument('uri', 'string', 'Action uri', true); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param array $arguments |
|
63
|
|
|
* @param \Closure $renderChildrenClosure |
|
64
|
|
|
* @param RenderingContextInterface $renderingContext |
|
65
|
|
|
* @throws Exception |
|
66
|
|
|
* @throws \InvalidArgumentException |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function renderStatic( |
|
69
|
|
|
array $arguments, |
|
70
|
|
|
\Closure $renderChildrenClosure, |
|
71
|
|
|
RenderingContextInterface $renderingContext |
|
72
|
|
|
) { |
|
73
|
|
|
trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED); |
|
74
|
|
|
$request = $renderingContext->getRequest(); |
|
|
|
|
|
|
75
|
|
|
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); |
|
76
|
|
|
self::ensureProperNesting($viewHelperVariableContainer); |
|
77
|
|
|
|
|
78
|
|
|
/** @var Menu $menu */ |
|
79
|
|
|
$menu = $viewHelperVariableContainer->get(ModuleLayoutViewHelper::class, Menu::class); |
|
80
|
|
|
$menuItem = $menu->makeMenuItem(); |
|
81
|
|
|
$menuItem->setTitle($arguments['label']); |
|
82
|
|
|
$menuItem->setHref($arguments['uri']); |
|
83
|
|
|
$menuItem->setActive($request->getAttribute('normalizedParams')->getRequestUri() === $arguments['uri']); |
|
84
|
|
|
$menu->addMenuItem($menuItem); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param ViewHelperVariableContainer $viewHelperVariableContainer |
|
89
|
|
|
* @throws Exception |
|
90
|
|
|
*/ |
|
91
|
|
|
private static function ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer): void |
|
92
|
|
|
{ |
|
93
|
|
|
if (!$viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, Menu::class)) { |
|
94
|
|
|
throw new Exception(sprintf('%s must be nested in <f.be.moduleLayout.menu> ViewHelper', self::class), 1531235592); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|