Skip to content
Snippets Groups Projects
menu.inc 111 KiB
Newer Older
  if ($save) {
    $path_roots = array_values($path_roots);
    // Update the path roots variable and reset the path alias whitelist cache
    // if the list has changed.
    if ($path_roots != \Drupal::state()->get('menu_path_roots')) {
      \Drupal::state()->set('menu_path_roots', array_values($path_roots));
      \Drupal::service('path.alias_manager')->cacheClear();
 * Saves data from menu_router_build() to the router table.
 */
function _menu_router_save($menu, $masks) {
  // Delete the existing router since we have some data to replace it.
  db_truncate('menu_router')->execute();
  // Prepare insert object.
  $insert = db_insert('menu_router')
    ->fields(array(
      'path',
      'load_functions',
      'to_arg_functions',
      'access_callback',
      'access_arguments',
      'page_callback',
      'page_arguments',
      'fit',
      'number_parts',
      'tab_parent',
      'tab_root',
      'title',
      'title_callback',
      'title_arguments',
      'type',
      'description',
      'description_callback',
      'description_arguments',
    // Fill in insert object values.
    $insert->values(array(
      'path' => $item['path'],
      'load_functions' => $item['load_functions'],
      'to_arg_functions' => $item['to_arg_functions'],
      'access_callback' => $item['access callback'],
      'access_arguments' => serialize($item['access arguments']),
      'page_callback' => $item['page callback'],
      'page_arguments' => serialize($item['page arguments']),
      'fit' => $item['_fit'],
      'number_parts' => $item['_number_parts'],
      'tab_parent' => $item['tab_parent'],
      'tab_root' => $item['tab_root'],
      'title' => $item['title'],
      'title_callback' => $item['title callback'],
      'title_arguments' => ($item['title arguments'] ? serialize($item['title arguments']) : ''),
      'type' => $item['type'],
      'description' => $item['description'],
      'description_callback' => $item['description callback'],
      'description_arguments' => ($item['description arguments'] ? serialize($item['description arguments']) : ''),
      'position' => $item['position'],
      'weight' => $item['weight'],

    // Execute in batches to avoid the memory overhead of all of those records
    // in the query object.
    if (++$num_records == 20) {
      $insert->execute();
      $num_records = 0;
    }
  \Drupal::state()->set('menu.masks', $masks);
 * Checks whether the site is in maintenance mode.
 *
 * This function will log the current user out and redirect to front page
 * if the current user has no 'access site in maintenance mode' permission.
 * @param $check_only
 *   If this is set to TRUE, the function will perform the access checks and
 *   return the site offline status, but not log the user out or display any
 *   messages.
 *   FALSE if the site is not in maintenance mode, the user login page is
 *   displayed, or the user has the 'access site in maintenance mode'
 *   permission. TRUE for anonymous users not being on the login page when the
 *   site is in maintenance mode.
function _menu_site_is_offline($check_only = FALSE) {
  // Check if site is in maintenance mode.
  if (\Drupal::state()->get('system.maintenance_mode')) {
    if (user_access('access site in maintenance mode')) {
      // Ensure that the maintenance mode message is displayed only once
      // (allowing for page redirects) and specifically suppress its display on
      // the maintenance mode settings page.
      if (!$check_only && current_path() != 'admin/config/development/maintenance') {
        if (user_access('administer site configuration')) {
          drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance'))), 'status', FALSE);
        }
        else {
          drupal_set_message(t('Operating in maintenance mode.'), 'status', FALSE);
        }