Issue #1966298 by das-peter, andypost, Gábor Hojtsy, amateescu, YesCT: Introduce menu link bundles per menus.
parent
5a31f62c0e
commit
5165b47b10
|
@ -39,6 +39,29 @@ function book_help($path, $arg) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info().
|
||||
*/
|
||||
function book_entity_bundle_info() {
|
||||
$bundles['menu_link']['book-toc'] = array(
|
||||
'label' => t('Book'),
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_TYPE_load().
|
||||
*/
|
||||
function book_menu_link_load($entities) {
|
||||
foreach ($entities as $entity) {
|
||||
// Change the bundle of menu links related to a book.
|
||||
if (strpos($entity->menu_name, 'book-toc-') === 0) {
|
||||
$entity->bundle = 'book-toc';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
|
|
|
@ -332,6 +332,30 @@ class MenuTest extends WebTestBase {
|
|||
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure odd first"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '/configure?destination=test-page">Configure block</a></li><li class="menu-edit even last"><a href="' . base_path() . 'admin/structure/menu/manage/tools/edit?destination=test-page">Edit menu</a></li></ul>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests menu link bundles.
|
||||
*/
|
||||
public 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 menu');
|
||||
|
||||
$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 menu');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a menu link using the menu module UI.
|
||||
*
|
||||
|
|
|
@ -152,6 +152,22 @@ function menu_entity_info_alter(&$entity_info) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info().
|
||||
*/
|
||||
function menu_entity_bundle_info() {
|
||||
$bundles = array();
|
||||
$config_names = config_get_storage_names_with_prefix('menu.menu.');
|
||||
foreach ($config_names as $config_name) {
|
||||
$config = config($config_name);
|
||||
$bundles['menu_link'][$config->get('id')] = array(
|
||||
'label' => $config->get('label'),
|
||||
);
|
||||
}
|
||||
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity URI callback.
|
||||
*
|
||||
|
|
|
@ -104,6 +104,9 @@ class MenuLinkStorageController extends DatabaseStorageController {
|
|||
// Use the weight property from the menu link.
|
||||
$menu_link->router_item['weight'] = $menu_link->weight;
|
||||
|
||||
// By default use the menu_name as type.
|
||||
$menu_link->bundle = $menu_link->menu_name;
|
||||
|
||||
// For all links that have an associated route, load the route object now
|
||||
// and save it on the object. That way we avoid a select N+1 problem later.
|
||||
if ($menu_link->route_name) {
|
||||
|
|
|
@ -35,7 +35,11 @@ use Drupal\Core\Entity\Entity;
|
|||
* entity_keys = {
|
||||
* "id" = "mlid",
|
||||
* "label" = "link_title",
|
||||
* "uuid" = "uuid"
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "bundle"
|
||||
* },
|
||||
* bundle_keys = {
|
||||
* "bundle" = "bundle"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
|
@ -48,6 +52,13 @@ class MenuLink extends Entity implements \ArrayAccess, MenuLinkInterface {
|
|||
*/
|
||||
public $menu_name = 'tools';
|
||||
|
||||
/**
|
||||
* The link's bundle.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $bundle = 'tools';
|
||||
|
||||
/**
|
||||
* The menu link ID.
|
||||
*
|
||||
|
@ -253,6 +264,13 @@ class MenuLink extends Entity implements \ArrayAccess, MenuLinkInterface {
|
|||
return $this->mlid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function bundle() {
|
||||
return $this->bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Entity::createDuplicate().
|
||||
*/
|
||||
|
|
|
@ -38,6 +38,29 @@ function shortcut_help($path, $arg) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info().
|
||||
*/
|
||||
function shortcut_entity_bundle_info() {
|
||||
$bundles['menu_link']['shortcut'] = array(
|
||||
'label' => t('Shortcut'),
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_TYPE_load().
|
||||
*/
|
||||
function shortcut_menu_link_load($entities) {
|
||||
foreach ($entities as $entity) {
|
||||
// Change the bundle of menu links related to a shortcut.
|
||||
if (strpos($entity->menu_name, 'shortcut-') === 0) {
|
||||
$entity->bundle = 'shortcut';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue