TYPO3 CMS  TYPO3_8-7
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 }
static makeInstance($className,... $constructorArguments)