2 namespace TYPO3\CMS\Frontend\ContentObject\Menu
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
18 * Factory for menu content objects. Allows overriding the default
19 * types like 'GMENU' with an own implementation (only one possible)
20 * and new types can be registered.
22 * @author Christian Kuhn <lolli@schwarzbu.ch>
24 class MenuContentObjectFactory
implements \TYPO3\CMS\Core\SingletonInterface
{
27 * Register of TypoScript keys to according render class
31 protected $menuTypeToClassMapping = array(
32 'GMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\GraphicalMenuContentObject
::class,
33 'TMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\TextMenuContentObject
::class,
34 'IMGMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject
::class,
35 'JSMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\JavaScriptMenuContentObject
::class,
39 * Gets a typo script string like 'TMENU' and returns an object of this type
42 * @return object Menu object
43 * @throws Exception\NoSuchMenuTypeException
45 public function getMenuObjectByType($type = '') {
46 $uppercasedClassname = strtoupper($type);
47 if (array_key_exists($uppercasedClassname, $this->menuTypeToClassMapping
)) {
48 $object = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance($this->menuTypeToClassMapping
[$uppercasedClassname]);
50 throw new Exception\
NoSuchMenuTypeException(
51 'Menu type ' . (string)$type . ' has no implementing class.',
59 * Register new menu type or override existing type
61 * @param string $type Menu type to be used in TypoScript
62 * @param string $className Class rendering the menu
63 * @throws \InvalidArgumentException
65 public function registerMenuType($type, $className) {
66 if (!is_string($type) ||
!is_string($className)) {
67 throw new \
InvalidArgumentException(
68 'type and className must be strings',
72 $this->menuTypeToClassMapping
[strtoupper($type)] = $className;