You are here

function _site_map_menus in Site map 8

Same name and namespace in other branches
  1. 5 site_map.module \_site_map_menus()
  2. 6.2 site_map.module \_site_map_menus()
  3. 6 site_map.module \_site_map_menus()
  4. 7 site_map.module \_site_map_menus()

Render the latest maps for all the menus.

Return value

string Returns HTML string of site map for menus.

1 call to _site_map_menus()
template_preprocess_site_map in ./site_map.theme.inc
Preprocesses the variables for site-map.html.twig.

File

./site_map.module, line 375
Provides a site map functionality.

Code

function _site_map_menus($mid) {
  $output = '';
  $class = array();
  $options = array();
  if (!empty($mid)) {
    $menu = Menu::load($mid);

    // Retrieve the expanded tree.
    $tree = \Drupal::service('menu.link_tree')
      ->load($mid, new MenuTreeParameters());
    $manipulators = array(
      array(
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ),
      array(
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ),
    );
    $tree = \Drupal::service('menu.link_tree')
      ->transform($tree, $manipulators);
    if (\Drupal::service('module_handler')
      ->moduleExists('i18n_menu')) {
      $tree = i18n_menu_localize_tree($tree, $GLOBALS['language']->language);
    }

    // Add an alter hook so that other modules can manipulate the
    // menu tree prior to rendering.
    $alter_mid = preg_replace('/[^a-z0-9_]+/', '_', $mid);
    \Drupal::moduleHandler()
      ->alter(array(
      'site_map_menu_tree',
      'site_map_menu_tree_' . $alter_mid,
    ), $tree, $menu);
    $menu_display = \Drupal::service('menu.link_tree')
      ->buildForSiteMap($tree);
    $menu_html = drupal_render($menu_display);
    if (!empty($menu_html)) {
      $title = $menu
        ->label();
      if (\Drupal::service('module_handler')
        ->moduleExists('i18n_string')) {
        $m_array = array(
          'menu',
          'menu',
          $menu['menu_name'],
          'title',
        );
        $title = i18n_string_plain($m_array, $title);
      }
      \Drupal::service('site_map.helper')
        ->setOption($options, 'show_titles', 1, 'show_titles', TRUE);
      $class[] = 'site-map-box-menu';
      $class[] = 'site-map-box-menu-' . $mid;
      $attributes = array(
        'class' => $class,
      );
      $site_map_box = array(
        '#theme' => 'site_map_box',
        '#title' => $title,
        '#content' => $menu_html,
        '#attributes' => $attributes,
        '#options' => $options,
      );
      $output .= drupal_render($site_map_box);
    }
  }
  return $output;
}