‪TYPO3CMS  10.4
MenuContentObjectFactory.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 
21 
29 {
35  protected ‪$menuTypeToClassMapping = [
36  'TMENU' => TextMenuContentObject::class,
37  ];
38 
46  public function ‪getMenuObjectByType($type = '')
47  {
48  $upperCasedClassName = strtoupper($type);
49  if (array_key_exists($upperCasedClassName, $this->menuTypeToClassMapping)) {
51  $object = GeneralUtility::makeInstance($this->menuTypeToClassMapping[$upperCasedClassName]);
52  } else {
54  'Menu type ' . (string)$type . ' has no implementing class.',
55  1363278130
56  );
57  }
58  return $object;
59  }
60 
68  public function ‪registerMenuType($type, $className)
69  {
70  if (!is_string($type) || !is_string($className)) {
71  throw new \InvalidArgumentException(
72  'type and className must be strings',
73  1363429303
74  );
75  }
76  $this->menuTypeToClassMapping[strtoupper($type)] = $className;
77  }
78 }
‪TYPO3\CMS\Frontend\ContentObject\Menu\Exception\NoSuchMenuTypeException
Definition: NoSuchMenuTypeException.php:24
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
Definition: AbstractMenuContentObject.php:46
‪TYPO3\CMS\Frontend\ContentObject\Menu\MenuContentObjectFactory\$menuTypeToClassMapping
‪array $menuTypeToClassMapping
Definition: MenuContentObjectFactory.php:34
‪TYPO3\CMS\Frontend\ContentObject\Menu
Definition: AbstractMenuContentObject.php:16
‪TYPO3\CMS\Frontend\ContentObject\Menu\MenuContentObjectFactory\getMenuObjectByType
‪AbstractMenuContentObject getMenuObjectByType($type='')
Definition: MenuContentObjectFactory.php:45
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Frontend\ContentObject\Menu\MenuContentObjectFactory\registerMenuType
‪registerMenuType($type, $className)
Definition: MenuContentObjectFactory.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\ContentObject\Menu\MenuContentObjectFactory
Definition: MenuContentObjectFactory.php:29