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