You are here

public function UltimenuManager::getRegions in Ultimenu 8

Same name and namespace in other branches
  1. 8.2 src/UltimenuManager.php \Drupal\ultimenu\UltimenuManager::getRegions()

The array of available Ultimenu regions based on enabled menu items.

Return value

array An array of regions definition dependent on available menu items.

Overrides UltimenuManagerInterface::getRegions

2 calls to UltimenuManager::getRegions()
UltimenuManager::getEnabledRegions in src/UltimenuManager.php
Returns the array of enabled Ultimenu regions based on enabled settings.
UltimenuManager::parseThemeInfo in src/UltimenuManager.php
Returns the default theme Ultimenu regions from theme .info.yml.

File

src/UltimenuManager.php, line 440

Class

UltimenuManager
Manages Ultimenu plugin.

Namespace

Drupal\ultimenu

Code

public function getRegions() {
  if (!isset($this->regions)) {
    $blocks = $this
      ->getSetting('blocks');
    $menu_blocks = is_array($blocks) ? array_filter($blocks) : [
      $blocks,
    ];
    $menus = [];
    foreach ($menu_blocks as $delta => $title) {
      $menus[$delta] = $this
        ->loadMenuTree($delta);
    }

    // Allow alteration.
    $this->moduleHandler
      ->alter('ultimenu_menus_info', $menus);
    $this->regions = [];
    foreach ($menus as $menu_name => $tree) {
      $tree = $this->menuTree
        ->build($tree);
      if (isset($tree['#items'])) {
        foreach ($tree['#items'] as $key => $item) {
          $name_id = $this
            ->truncateRegionKey($menu_name);
          $name_id_nice = str_replace("_", " ", $name_id);
          if ($item['title']) {
            $menu_title = strip_tags($item['title']);
            $region_key = $this
              ->getRegionKey($menu_name, $key, $menu_title);
            $this->regions[$region_key] = "Ultimenu:{$name_id_nice}: {$menu_title}";
            $this->regions = array_unique($this->regions);
          }
        }
      }
    }

    // Allow alteration.
    $this->moduleHandler
      ->alter('ultimenu_regions_info', $this->regions);
  }
  return $this->regions;
}