You are here

public function SimpleMegaMenuHelper::getMegaMenuTypeWhichTargetMenu in Simple Mega Menu 2.0.x

Same name and namespace in other branches
  1. 8 src/SimpleMegaMenuHelper.php \Drupal\simple_megamenu\SimpleMegaMenuHelper::getMegaMenuTypeWhichTargetMenu()

Get SimpleMegaMenuType entities which target a menu.

Parameters

string $menu_name: The menu name.

Return value

array An array keyed by the SimpleMegaMenuType id and with the label as value. Otherwise, an empty array.

Overrides SimpleMegaMenuHelperInterface::getMegaMenuTypeWhichTargetMenu

File

src/SimpleMegaMenuHelper.php, line 42

Class

SimpleMegaMenuHelper
Class SimpleMegaMenuHelper.

Namespace

Drupal\simple_megamenu

Code

public function getMegaMenuTypeWhichTargetMenu($menu_name) {
  $mega_menu_types = [];
  $simple_mega_menu_types = $this->entityTypeManager
    ->getStorage('simple_mega_menu_type')
    ->loadMultiple();

  /** @var \Drupal\simple_megamenu\Entity\SimpleMegaMenuType $entity */
  foreach ($simple_mega_menu_types as $id => $entity) {
    $target_menus = $this
      ->getTargetMenus($entity);
    if (in_array($menu_name, $target_menus)) {
      $mega_menu_types[$id] = $entity
        ->label();
    }
  }
  return $mega_menu_types;
}