menu.install

Install, update and uninstall functions for the menu module.

File

drupal/core/modules/menu/menu.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the menu module.
 */
use Drupal\Component\Uuid\Uuid;

/**
 * Implements hook_uninstall().
 */
function menu_uninstall() {
  menu_router_rebuild();
}

/**
 * Moves menu settings from variables to config.
 *
 * @ingroup config_upgrade
 */
function menu_update_8000() {
  update_variables_to_config('menu.settings', array(
    'menu_main_links_source' => 'main_links',
    'menu_secondary_links_source' => 'secondary_links',
  ));
}

/**
 * Rename default menu names.
 */
function menu_update_8001() {

  // Only the internal identifiers are updated; the labels and descriptions
  // might have been customized and do not have to be renamed.
  $map = array(
    'navigation' => 'tools',
    'management' => 'admin',
    'user-menu' => 'account',
    'main-menu' => 'main',
  );
  foreach ($map as $old => $new) {
    db_update('menu_custom')
      ->condition('menu_name', $old)
      ->fields(array(
      'menu_name' => $new,
    ))
      ->execute();
  }
}

/**
 * Adds the footer menu to custom menus.
 */
function menu_update_8002() {
  db_insert('menu_custom')
    ->fields(array(
    'menu_name' => 'footer',
    'title' => 'Footer menu',
    'description' => 'Use this for linking to site information.',
  ))
    ->execute();
}

/**
 * Moves menu_override_parent_selector from variables to config.
 *
 * @ingroup config_upgrade
 */
function menu_update_8003() {
  update_variables_to_config('menu.settings', array(
    'menu_override_parent_selector' => 'override_parent_selector',
  ));
}

/**
 * Migrate menus into configuration.
 *
 * @ingroup config_upgrade
 */
function menu_update_8004() {
  $uuid = new Uuid();
  $result = db_query('SELECT * FROM {menu_custom}');
  foreach ($result as $menu) {

    // Save the config object.
    config('menu.menu.' . $menu->menu_name)
      ->set('id', $menu->menu_name)
      ->set('uuid', $uuid
      ->generate())
      ->set('label', $menu->title)
      ->set('description', $menu->description)
      ->save();
  }
}

Functions

Namesort descending Description
menu_uninstall Implements hook_uninstall().
menu_update_8000 Moves menu settings from variables to config.
menu_update_8001 Rename default menu names.
menu_update_8002 Adds the footer menu to custom menus.
menu_update_8003 Moves menu_override_parent_selector from variables to config.
menu_update_8004 Migrate menus into configuration.