You are here

public function FootermapBlock::buildMap in footermap: a footer site map 8

Build content for footer site map.

The default implementation should call buildMenu() recursively.

This deprecates footermap_render().

@todo The return value may change by the time Drupal 8 is released.

Return value

array An associative array ready for render system.

Overrides FootermapInterface::buildMap

See also

Drupal\footermap\Plugin\Block\Footermap::buildMenu()

1 call to FootermapBlock::buildMap()
FootermapBlock::build in src/Plugin/Block/FootermapBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/FootermapBlock.php, line 226

Class

FootermapBlock
Provide a footer-based site map block based on menu items.

Namespace

Drupal\footermap\Plugin\Block

Code

public function buildMap() {
  $this->mapref = [];

  // Assemble all of the configuration necessary to build footer map.
  $col_index = 1;
  $depth = $this->configuration['footermap_recurse_limit'] == 0 ? NULL : $this->configuration['footermap_recurse_limit'];
  $top_menu_plugin_id = $this->configuration['footermap_top_menu'] == '' ? FALSE : $this->configuration['footermap_top_menu'];
  $menus = $this
    ->getMenus($top_menu_plugin_id);
  $parameters = new MenuTreeParameters();

  // Set the maximum depth if not unlimited.
  if ($this->configuration['footermap_recurse_limit']) {
    $parameters
      ->setMaxDepth($depth);
  }
  $parameters
    ->onlyEnabledLinks();
  $parameters
    ->excludeRoot();

  // Set root if top menu plugin id set.
  if ($top_menu_plugin_id && !empty($menus)) {
    $parameters
      ->setRoot($top_menu_plugin_id);
  }

  // Menu link manipulator using anonymous session.
  $manipulators = [
    [
      'callable' => 'footermap.anonymous_tree_manipulator:checkAccess',
    ],
  ];
  foreach ($menus as $menu_name => $menu) {

    // Loop through every menu.
    if (isset($this->configuration['footermap_avail_menus'][$menu_name]) && $this->configuration['footermap_avail_menus'][$menu_name] === $menu_name) {

      // Only build site map for available menus.
      $menu_name_class = str_replace('_', '-', $menu_name);
      $tree = $this->menuTree
        ->load($menu_name, $parameters);
      $tree = $this->menuTree
        ->transform($tree, $manipulators);
      if (!empty($tree)) {
        $this->mapref[$menu_name] = [
          '#theme' => 'footermap_header',
          // check_plain() during render.
          '#title' => $menu,
          '#title_display' => $this->configuration['footermap_display_heading'] ? 'visible' : 'hidden',
          '#menu_name' => $menu_name,
          '#attributes' => [
            'class' => [
              'footermap-header',
              'footermap-header--' . $menu_name_class,
            ],
          ],
        ];
        $this
          ->buildMenu($tree, $this->mapref[$menu_name]);
      }
      $col_index++;
    }
  }
  return $this->mapref;
}