diff --git a/core/modules/menu/lib/Drupal/menu/Controller/MenuController.php b/core/modules/menu/lib/Drupal/menu/Controller/MenuController.php new file mode 100644 index 0000000..a2b69a8 --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Controller/MenuController.php @@ -0,0 +1,98 @@ +entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity') + ); + } + + /** + * Shows an overview page of all the custom menus and their descriptions. + * + * @return array + * A render array of the listing page. + */ + public function overview() { + return $this->entityManager->getListController('menu')->render(); + } + + /** + * Gets all the available menus and menu items as a JavaScript array. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The request of the page. + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + * The available menu and menu items. + */ + public function getParentOptions(Request $request) { + $available_menus = array(); + if ($menus = $request->request->get('menus')) { + foreach ($menus as $menu) { + $available_menus[$menu] = $menu; + } + } + $options = _menu_get_options(menu_get_menus(), $available_menus, array('mlid' => 0)); + + return new JsonResponse($options); + } + + /** + * Provides the menu link submission form. + * + * @param \Drupal\system\Plugin\Core\Entity\Menu $menu + * An entity representing a custom menu. + * + * @return array + * Returns the menu link submission form. + */ + public function addLink(Menu $menu) { + drupal_set_title(t('Add menu link')); + $menu_link = $this->entityManager->getStorageController('menu_link')->create(array( + 'mlid' => 0, + 'plid' => 0, + 'menu_name' => $menu->id(), + )); + return entity_get_form($menu_link); + } + +} diff --git a/core/modules/menu/lib/Drupal/menu/MenuFormController.php b/core/modules/menu/lib/Drupal/menu/MenuFormController.php index 4eeab27..5fd91c5 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuFormController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.php @@ -8,6 +8,7 @@ namespace Drupal\menu; use Drupal\Core\Entity\EntityFormController; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base form controller for menu edit forms. @@ -15,10 +16,15 @@ class MenuFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * {@inheritdoc} */ public function form(array $form, array &$form_state) { $form = parent::form($form, $form_state); + + if ($this->operation == 'edit') { + drupal_set_title(t('Edit menu %label', array('%label' => $this->entity->label())), PASS_THROUGH); + } + $menu = $this->entity; $system_menus = menu_list_system_menus(); $form_state['menu'] = &$menu; @@ -36,7 +42,7 @@ public function form(array $form, array &$form_state) { '#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI, '#description' => t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'), '#machine_name' => array( - 'exists' => 'menu_edit_menu_name_exists', + 'exists' => array($this, 'menuNameExists'), 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-', @@ -53,6 +59,7 @@ public function form(array $form, array &$form_state) { // Add menu links administration form for existing menus. if (!$menu->isNew() || isset($system_menus[$menu->id()])) { + form_load_include($form_state, 'admin.inc', 'menu'); // Form API supports constructing and validating self-contained sections // within forms, but does not allow to handle the form section's submission // equally separated yet. Therefore, we use a $form_state key to point to @@ -67,7 +74,27 @@ public function form(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::actions(). + * Returns whether a menu name already exists. + * + * @param string $value + * The name of the menu. + * + * @return bool + * Returns TRUE if the menu already exists. + * + * @see form_validate_machine_name() + */ + public function menuNameExists($value) { + $custom_exists = entity_load('menu', $value); + // 'menu-' is added to the menu name to avoid name-space conflicts. + $value = 'menu-' . $value; + $link_exists = \Drupal::entityQuery('menu_link')->condition('menu_name', $value)->range(0,1)->count()->execute(); + + return $custom_exists || $link_exists; + } + + /** + * {@inheritdoc} */ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); @@ -80,7 +107,7 @@ protected function actions(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * {@inheritdoc} */ public function save(array $form, array &$form_state) { $menu = $this->entity; @@ -111,7 +138,7 @@ public function save(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::delete(). + * {@inheritdoc} */ public function delete(array $form, array &$form_state) { $menu = $this->entity; diff --git a/core/modules/menu/lib/Drupal/menu/MenuListController.php b/core/modules/menu/lib/Drupal/menu/MenuListController.php index e557d92..448f729 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuListController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuListController.php @@ -48,7 +48,7 @@ public function getOperations(EntityInterface $entity) { $uri = $entity->uri(); $operations['edit']['title'] = t('Edit menu'); - $operatuins['edit']['href'] = $uri['path']; + $operations['edit']['href'] = $uri['path']; $operations['add'] = array( 'title' => t('Add link'), 'href' => $uri['path'] . '/add', diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index a5c5456..69c288c 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -187,7 +187,7 @@ function deleteCustomMenu($menu) { $this->assertFalse($result, 'All menu links associated to the custom menu were deleted.'); // Make sure there's no delete button on system menus. - $this->drupalGet('admin/structure/menu/manage/main/edit'); + $this->drupalGet('admin/structure/menu/manage/main'); $this->assertNoRaw('edit-delete', 'The delete button was not found'); // Try to delete the main menu. @@ -294,7 +294,7 @@ function testSystemMenuRename() { $edit = array( 'label' => $this->randomName(16), ); - $this->drupalPost('admin/structure/menu/manage/main/edit', $edit, t('Save')); + $this->drupalPost('admin/structure/menu/manage/main', $edit, t('Save')); // Make sure menu shows up with new name in block addition. $default_theme = variable_get('theme_default', 'stark'); diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index 4150b99..5752eb2 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -6,47 +6,7 @@ */ use Drupal\menu_link\Plugin\Core\Entity\MenuLink; -use Drupal\system\Plugin\Core\Entity\Menu; use Drupal\Component\Utility\NestedArray; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; - -/** - * Menu callback which shows an overview page of all the custom menus and their descriptions. - */ -function menu_overview_page() { - return Drupal::entityManager() - ->getListController('menu') - ->render(); -} - -/** - * Page callback: Presents the menu creation form. - * - * @return array - * A form array as expected by drupal_render(). - * - * @see menu_menu() - */ -function menu_menu_add() { - $menu = entity_create('menu', array()); - return entity_get_form($menu); -} - -/** - * Page callback: Presents the menu edit form. - * - * @param \Drupal\system\Plugin\Core\Entity\Menu $menu - * The menu to edit. - * - * @return array - * A form array as expected by drupal_render(). - * - * @see menu_menu() - */ -function menu_menu_edit(Menu $menu) { - drupal_set_title(t('Edit menu %label', array('%label' => $menu->label())), PASS_THROUGH); - return entity_get_form($menu); -} /** * Form constructor to edit an entire menu tree at once. @@ -94,20 +54,6 @@ function menu_overview_form($form, &$form_state) { menu_tree_check_access($tree, $node_links); $menu_admin = FALSE; - // Inline the "Add link" action so it displays right above the table of - // links. No access check needed, since this form has the same access - // restriction as adding menu items to the menu. - $form['inline_actions'] = array( - '#prefix' => '