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