Mercurial > hg > isophonics-drupal-site
comparison core/modules/menu_ui/src/Controller/MenuController.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\menu_ui\Controller; | |
4 | |
5 use Drupal\Component\Utility\Xss; | |
6 use Drupal\Core\Controller\ControllerBase; | |
7 use Drupal\Core\Menu\MenuParentFormSelectorInterface; | |
8 use Drupal\system\MenuInterface; | |
9 use Symfony\Component\DependencyInjection\ContainerInterface; | |
10 use Symfony\Component\HttpFoundation\JsonResponse; | |
11 use Symfony\Component\HttpFoundation\Request; | |
12 | |
13 /** | |
14 * Returns responses for Menu routes. | |
15 */ | |
16 class MenuController extends ControllerBase { | |
17 | |
18 /** | |
19 * The menu parent form service. | |
20 * | |
21 * @var \Drupal\Core\Menu\MenuParentFormSelectorInterface | |
22 */ | |
23 protected $menuParentSelector; | |
24 | |
25 /** | |
26 * Creates a new MenuController object. | |
27 * | |
28 * @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_form | |
29 * The menu parent form service. | |
30 */ | |
31 public function __construct(MenuParentFormSelectorInterface $menu_parent_form) { | |
32 $this->menuParentSelector = $menu_parent_form; | |
33 } | |
34 | |
35 /** | |
36 * {@inheritdoc} | |
37 */ | |
38 public static function create(ContainerInterface $container) { | |
39 return new static($container->get('menu.parent_form_selector')); | |
40 } | |
41 | |
42 /** | |
43 * Gets all the available menus and menu items as a JavaScript array. | |
44 * | |
45 * @param \Symfony\Component\HttpFoundation\Request $request | |
46 * The request of the page. | |
47 * | |
48 * @return \Symfony\Component\HttpFoundation\JsonResponse | |
49 * The available menu and menu items. | |
50 */ | |
51 public function getParentOptions(Request $request) { | |
52 $available_menus = []; | |
53 if ($menus = $request->request->get('menus')) { | |
54 foreach ($menus as $menu) { | |
55 $available_menus[$menu] = $menu; | |
56 } | |
57 } | |
58 // @todo Update this to use the optional $cacheability parameter, so that | |
59 // a cacheable JSON response can be sent. | |
60 $options = $this->menuParentSelector->getParentSelectOptions('', $available_menus); | |
61 | |
62 return new JsonResponse($options); | |
63 } | |
64 | |
65 /** | |
66 * Route title callback. | |
67 * | |
68 * @param \Drupal\system\MenuInterface $menu | |
69 * The menu entity. | |
70 * | |
71 * @return array | |
72 * The menu label as a render array. | |
73 */ | |
74 public function menuTitle(MenuInterface $menu) { | |
75 return ['#markup' => $menu->label(), '#allowed_tags' => Xss::getHtmlTagList()]; | |
76 } | |
77 | |
78 } |