Posted by andypost on January 14, 2013 at 5:50pm
Project:
Drupal core
Introduced in branch:
8.x Description:
As a part of #1802750: [Meta] Convert configurable data to ConfigEntity system
The {menu_custom} table has been removed in favor of a new menu config entity. The table is preserved in installations upgraded from earlier versions of Drupal to allow contrib modules to migrate their data, See #1860986: Drop left-over tables from 8.x
Summary
- $menu becomes a classed object,
Drupal\system\Plugin\Core\Entity\Menu. - Wherever the code refers to the menu_name, use
$menu->id(). - Wherever the code intends to output a name for the menu, use
$menu->label().
API changes
field_ui_menu_load()renamed tofield_ui_instance_load()to not firehook_menu_load()as implementation ofhook_ENTITY_TYPE_load(). Contrib modules should check their function names too.- Removed
menu_load_all(),menu_save()andmenu_delete()use entity API methods instead. - All
hook_menu_*()hooks now receive\Drupal\system\Plugin\Core\Entity\Menu $menuas parameter and just ahook_ENTITY_TYPE_*()hooks - Menu add/edit forms now use the entity form controller
MenuFormController. - Administration page uses the entity list controller
MenuListController,menu_admin_overview()has been removed.
Examples
<?php
// D7 code
$menus = menu_load_all();
foreach ($menus as $menu) {
//...
?><?php
// D8 code
$menus = entity_load_multiple('menu');
foreach ($menus as $menu) {
//...
?>Entity API
<?php
// D7 code
$menu = array(
'menu_name' => $menu_machine_name,
'title' => 'Custom menu human-readable name',
'description' => 'Description text',
);
menu_save($menu);
?><?php
// D8 code
$menu = entity_create('menu', array(
'id' => $menu_machine_name,
'label' => 'Custom menu human-readable name',
'description' => 'Description text',
));
$menu->save();
?>Hooks
<?php
// D7 code
function hook_menu_delete($menu) {
// Delete the record from our variable.
$my_menus = variable_get('my_module_menus', array());
unset($my_menus[$menu['menu_name']]);
variable_set('my_module_menus', $my_menus);
}
?><?php
// D8 code
function hook_menu_delete($menu) {
// Delete the record from our variable.
$my_menus = variable_get('my_module_menus', array());
unset($my_menus[$menu->id()]);
variable_set('my_module_menus', $my_menus);
}
?>Impacts:
Site builders, administrators, editors
Module developers
Themers