By andypost on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
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. - As do all configuration entities, menus now have a
langcodeproperty.
Examples
// D7 code
$menus = menu_load_all();
foreach ($menus as $menu) {
//...
// D8 code
$menus = Menu::loadMultiple();
foreach ($menus as $menu) {
//...
Entity API
// D7 code
$menu = array(
'menu_name' => $menu_machine_name,
'title' => 'Custom menu human-readable name',
'description' => 'Description text',
);
menu_save($menu);
// D8 code
$menu = Menu::create(array(
'id' => $menu_machine_name,
'label' => 'Custom menu human-readable name',
'description' => 'Description text',
));
$menu->save();
Hooks
// 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);
}
// 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
Comments
For the next person that
For the next person that comes along, you need to use \Drupal\system\Entity\Menu