‪TYPO3CMS  10.4
MenuViewHelper.php
Go to the documentation of this file.
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 
19 
23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
27 use TYPO3Fluid\Fluid\View\Exception;
28 
46 class ‪MenuViewHelper extends AbstractViewHelper
47 {
48  use CompileWithRenderStatic;
49 
55  public function ‪initializeArguments()
56  {
57  $this->registerArgument('identifier', 'string', 'Identifier of the menu', true);
58  }
59 
66  public static function ‪renderStatic(
67  array $arguments,
68  \Closure $renderChildrenClosure,
69  RenderingContextInterface $renderingContext
70  ) {
71  $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
72  ‪self::ensureProperNesting($viewHelperVariableContainer);
73 
75  $moduleTemplate = $viewHelperVariableContainer->get(ModuleLayoutViewHelper::class, ModuleTemplate::class);
76  $menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
77  $menu->setIdentifier($arguments['identifier']);
78 
79  $viewHelperVariableContainer->add(ModuleLayoutViewHelper::class, Menu::class, $menu);
80  $renderChildrenClosure();
81  $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
82  $viewHelperVariableContainer->remove(ModuleLayoutViewHelper::class, Menu::class);
83  }
84 
89  private static function ‪ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer): void
90  {
91  if (!$viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, ModuleTemplate::class)) {
92  throw new Exception(sprintf('%s must be nested in <f.be.moduleLayout> ViewHelper', self::class), 1531235715);
93  }
94  if ($viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, Menu::class)) {
95  throw new Exception(sprintf('%s can not be nested in <f.be.moduleLayout.menu> ViewHelper', self::class), 1531235777);
96  }
97  }
98 }
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\MenuViewHelper\ensureProperNesting
‪static ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer)
Definition: MenuViewHelper.php:88
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\MenuViewHelper\initializeArguments
‪initializeArguments()
Definition: MenuViewHelper.php:54
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\MenuViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: MenuViewHelper.php:65
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu
Definition: Menu.php:24
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper
Definition: ModuleLayoutViewHelper.php:48
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\MenuViewHelper
Definition: MenuViewHelper.php:47
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout