TYPO3  7.6
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 
90  public function addMenuItem(MenuItem $menuItem)
91  {
92  if (!$menuItem->isValid($menuItem)) {
93  throw new \InvalidArgumentException('MenuItem "' . $menuItem->getTitle() . '" is not valid', 1442236317);
94  }
95  // @todo implement sorting of menu items
96  // @todo maybe even things like spacers/sections?
97  $this->menuItems[] = clone $menuItem;
98  }
99 
105  public function getMenuItems()
106  {
107  return $this->menuItems;
108  }
109 
115  public function getIdentifier()
116  {
117  return $this->identifier;
118  }
119 
125  public function makeMenuItem()
126  {
127  $menuItem = GeneralUtility::makeInstance(MenuItem::class);
128  return $menuItem;
129  }
130 
138  public function isValid(Menu $menu)
139  {
140  return (trim($menu->getIdentifier()) !== '');
141  }
142 }