Change record status: 
Project: 
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 to field_ui_instance_load() to not fire hook_menu_load() as implementation of hook_ENTITY_TYPE_load(). Contrib modules should check their function names too.
  • Removed menu_load_all(), menu_save() and menu_delete() use entity API methods instead.
  • All hook_menu_*() hooks now receive \Drupal\system\Plugin\Core\Entity\Menu $menu as parameter and just a hook_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.
  • As do all configuration entities, menus now have a langcode property.

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
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done