‪TYPO3CMS  10.4
Menu.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
23 class ‪Menu
24 {
30  protected ‪$identifier = '';
31 
37  protected ‪$label = '';
38 
44  protected ‪$menuItems = [];
45 
51  public function ‪getLabel()
52  {
53  return ‪$this->label;
54  }
55 
63  public function ‪setLabel(‪$label)
64  {
65  $this->label = ‪$label;
66  return $this;
67  }
68 
76  public function ‪setIdentifier(‪$identifier)
77  {
78  $this->identifier = ‪$identifier;
79  return $this;
80  }
81 
89  public function ‪addMenuItem(‪MenuItem $menuItem)
90  {
91  if (!$menuItem->‪isValid($menuItem)) {
92  throw new \InvalidArgumentException('MenuItem "' . $menuItem->‪getTitle() . '" is not valid', 1442236317);
93  }
94  // @todo implement sorting of menu items
95  // @todo maybe even things like spacers/sections?
96  $this->menuItems[] = clone $menuItem;
97  }
98 
104  public function ‪getMenuItems()
105  {
106  return ‪$this->menuItems;
107  }
108 
114  public function ‪getIdentifier()
115  {
116  return ‪$this->identifier;
117  }
118 
124  public function ‪getDataIdentifier(): string
125  {
126  $dataMenuIdentifier = ‪GeneralUtility::camelCaseToLowerCaseUnderscored($this->identifier);
127  $dataMenuIdentifier = str_replace('_', '-', $dataMenuIdentifier);
128  return $dataMenuIdentifier;
129  }
130 
136  public function ‪makeMenuItem()
137  {
138  $menuItem = GeneralUtility::makeInstance(MenuItem::class);
139  return $menuItem;
140  }
141 
149  public function ‪isValid(‪Menu $menu)
150  {
151  return trim($menu->‪getIdentifier()) !== '';
152  }
153 }
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\makeMenuItem
‪MenuItem makeMenuItem()
Definition: Menu.php:133
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$label
‪string $label
Definition: Menu.php:35
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getMenuItems
‪array getMenuItems()
Definition: Menu.php:101
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$identifier
‪string $identifier
Definition: Menu.php:29
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\setIdentifier
‪Menu setIdentifier($identifier)
Definition: Menu.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility\camelCaseToLowerCaseUnderscored
‪static string camelCaseToLowerCaseUnderscored($string)
Definition: GeneralUtility.php:914
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\setLabel
‪Menu setLabel($label)
Definition: Menu.php:60
‪TYPO3\CMS\Backend\Template\Components\Menu\MenuItem
Definition: MenuItem.php:24
‪TYPO3\CMS\Backend\Template\Components\Menu\MenuItem\isValid
‪bool isValid(MenuItem $menuItem)
Definition: MenuItem.php:90
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\$menuItems
‪array $menuItems
Definition: Menu.php:41
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getTitle
‪string getTitle()
Definition: AbstractControl.php:64
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getIdentifier
‪string getIdentifier()
Definition: Menu.php:111
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\isValid
‪bool isValid(Menu $menu)
Definition: Menu.php:146
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu
Definition: Menu.php:24
‪TYPO3\CMS\Backend\Template\Components\Menu
Definition: Menu.php:16
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getDataIdentifier
‪string getDataIdentifier()
Definition: Menu.php:121
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\addMenuItem
‪addMenuItem(MenuItem $menuItem)
Definition: Menu.php:86
‪TYPO3\CMS\Backend\Template\Components\Menu\Menu\getLabel
‪string getLabel()
Definition: Menu.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46