‪TYPO3CMS  9.5
Menu.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
22 class ‪Menu
23 {
29  protected ‪$identifier = '';
30 
36  protected ‪$label = '';
37 
43  protected ‪$menuItems = [];
44 
50  public function ‪getLabel()
51  {
52  return ‪$this->label;
53  }
54 
62  public function ‪setLabel(‪$label)
63  {
64  $this->label = ‪$label;
65  return $this;
66  }
67 
75  public function ‪setIdentifier(‪$identifier)
76  {
77  $this->identifier = ‪$identifier;
78  return $this;
79  }
80 
88  public function ‪addMenuItem(‪MenuItem $menuItem)
89  {
90  if (!$menuItem->‪isValid($menuItem)) {
91  throw new \InvalidArgumentException('MenuItem "' . $menuItem->‪getTitle() . '" is not valid', 1442236317);
92  }
93  // @todo implement sorting of menu items
94  // @todo maybe even things like spacers/sections?
95  $this->menuItems[] = clone $menuItem;
96  }
97 
103  public function ‪getMenuItems()
104  {
105  return ‪$this->menuItems;
106  }
107 
113  public function ‪getIdentifier()
114  {
115  return ‪$this->identifier;
116  }
117 
123  public function ‪getDataIdentifier(): string
124  {
125  $dataMenuIdentifier = GeneralUtility::camelCaseToLowerCaseUnderscored($this->identifier);
126  $dataMenuIdentifier = str_replace('_', '-', $dataMenuIdentifier);
127  return $dataMenuIdentifier;
128  }
129 
135  public function ‪makeMenuItem()
136  {
137  $menuItem = GeneralUtility::makeInstance(MenuItem::class);
138  return $menuItem;
139  }
140 
148  public function ‪isValid(‪Menu $menu)
149  {
150  return trim($menu->‪getIdentifier()) !== '';
151  }
152 }
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\makeMenuItem
‪MenuItem makeMenuItem()
Definition: Menu.php:132
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$label
‪string $label
Definition: Menu.php:34
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getMenuItems
‪array getMenuItems()
Definition: Menu.php:100
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$identifier
‪string $identifier
Definition: Menu.php:28
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\setIdentifier
‪Menu setIdentifier($identifier)
Definition: Menu.php:72
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\setLabel
‪Menu setLabel($label)
Definition: Menu.php:59
‪TYPO3\CMS\Backend\Template\Components\Menu\MenuItem
Definition: MenuItem.php:23
‪TYPO3\CMS\Backend\Template\Components\Menu\MenuItem\isValid
‪bool isValid(MenuItem $menuItem)
Definition: MenuItem.php:89
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$menuItems
‪array $menuItems
Definition: Menu.php:40
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getTitle
‪string getTitle()
Definition: AbstractControl.php:63
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getIdentifier
‪string getIdentifier()
Definition: Menu.php:110
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\isValid
‪bool isValid(Menu $menu)
Definition: Menu.php:145
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu
Definition: Menu.php:23
‪TYPO3\CMS\Backend\Template\Components\Menu
Definition: Menu.php:2
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getDataIdentifier
‪string getDataIdentifier()
Definition: Menu.php:120
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\addMenuItem
‪addMenuItem(MenuItem $menuItem)
Definition: Menu.php:85
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getLabel
‪string getLabel()
Definition: Menu.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45