You are here

public function UltimenuManager::getRegions in Ultimenu 8.2

Same name and namespace in other branches
  1. 8 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::removeRegions in src/UltimenuManager.php
Returns unwanted Ultimenu regions for removal from theme .info.yml.

File

src/UltimenuManager.php, line 585

Class

UltimenuManager
Implements UltimenuManagerInterface.

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->tree
        ->loadMenuTree($delta);
    }
    $regions = [];
    foreach ($menus as $menu_name => $tree) {
      foreach ($tree as $item) {
        $name_id = $this->tool
          ->truncateRegionKey($menu_name);
        $name_id_nice = str_replace("_", " ", $name_id);
        $link = $item->link;
        $menu_title = $this->tool
          ->getTitle($link);
        $region_key = $this->tool
          ->getRegionKey($link);
        $regions[$region_key] = "Ultimenu:{$name_id_nice}: {$menu_title}";
      }
    }
    $this->regions = $regions;
  }
  return $this->regions;
}