diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index 6c3ed1a..2ec74dd 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -333,6 +333,30 @@ public function testBlockContextualLinks() { } /** + * Test menu link bundles. + */ + function testMenuBundles() { + $this->drupalLogin($this->big_user); + $menu = $this->addCustomMenu(); + $bundles = entity_get_bundles('menu_link'); + $this->assertTrue($bundles[$menu->id()]); + $menus = menu_list_system_menus(); + $menus[$menu->id()] = $menu->label(); + ksort($menus); + $this->assertIdentical(array_keys($bundles), array_keys($menus)); + + // Test if moving a menu link between menus changes the bundle. + $node = $this->drupalCreateNode(array('type' => 'article')); + $item = $this->addMenuLink(0, 'node/' . $node->nid, 'tools'); + $this->moveMenuLink($item, 0, $menu->id()); + $this->assertEqual($item->bundle(), 'tools', 'Menu link bundle matches the menue'); + + $moved_item = entity_load('menu_link', $item->id(), TRUE); + $this->assertNotEqual($moved_item->bundle(), $item->bundle(), 'Menu link bundle was changed'); + $this->assertEqual($moved_item->bundle(), $menu->id(), 'Menu link bundle matches the menue'); + } + + /** * Add a menu link using the menu module UI. * * @param integer $plid Parent menu link id. diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 93c2ed8..f08cbc5 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -150,6 +150,29 @@ function menu_entity_info_alter(&$entity_info) { $entity_info['menu']['controllers']['form'] = array( 'default' => 'Drupal\menu\MenuFormController', ); + if (isset($entity_info['menu_link'])) { + // During upgrades from 7.x to 8.x the menu_link module is enabled. Calls + // to entity_info() before this occurs will not have the menu_link key set. + $entity_info['menu_link']['entity_keys']['bundle'] = 'menu_name'; + $entity_info['menu_link']['bundle_keys']['bundle'] = 'menu_name'; + } +} + +/** + * Implements hook_entity_bundle_info(). + */ +function menu_entity_bundle_info() { + $bundles = array(); + $info = Drupal::entityManager()->getDefinition('menu'); + $config_names = config_get_storage_names_with_prefix($info['config_prefix'] . '.'); + foreach ($config_names as $config_name) { + $config = config($config_name); + $bundles['menu_link'][$config->get('id')] = array( + 'label' => $config->get('label'), + ); + } + + return $bundles; } /** diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php index af4c799..57cfb56 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php @@ -254,6 +254,18 @@ public function id() { } /** + * {@inheritdoc} + */ + public function bundle() { + // If the bundle key is set - use it. + $entity_info = $this->entityInfo(); + if (!empty($entity_info['entity_keys']['bundle'])) { + return $this->{$entity_info['entity_keys']['bundle']}; + } + return parent::bundle(); + } + + /** * Overrides Entity::createDuplicate(). */ public function createDuplicate() {