You are here

class SimpleMegaMenuHelper in Simple Mega Menu 8

Same name and namespace in other branches
  1. 2.0.x src/SimpleMegaMenuHelper.php \Drupal\simple_megamenu\SimpleMegaMenuHelper

Class SimpleMegaMenuHelper.

@package Drupal\simple_megamenu

Hierarchy

Expanded class hierarchy of SimpleMegaMenuHelper

1 string reference to 'SimpleMegaMenuHelper'
simple_megamenu.services.yml in ./simple_megamenu.services.yml
simple_megamenu.services.yml
1 service uses SimpleMegaMenuHelper
simple_megamenu.helper in ./simple_megamenu.services.yml
Drupal\simple_megamenu\SimpleMegaMenuHelper

File

src/SimpleMegaMenuHelper.php, line 13

Namespace

Drupal\simple_megamenu
View source
class SimpleMegaMenuHelper implements SimpleMegaMenuHelperInterface {

  /**
   * Drupal\Core\Entity\EntityTypeManagerInterface definition.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function getTargetMenus(SimpleMegaMenuTypeInterface $entity) {
    return array_filter($entity
      ->getTargetMenu());
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function menuIsTargetedByMegaMenuType($menu_name) {
    $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 $entity) {
      $target_menus = $this
        ->getTargetMenus($entity);
      if (in_array($menu_name, $target_menus)) {
        return TRUE;
      }
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getSimpleMegaMenuType($id) {
    $simpleMegaMenuType = $this->entityTypeManager
      ->getStorage('simple_mega_menu_type')
      ->load($id);
    return $simpleMegaMenuType;
  }

  /**
   * {@inheritdoc}
   */
  public function getSimpleMegaMenu($id) {
    $simpleMegaMenu = $this->entityTypeManager
      ->getStorage('simple_mega_menu')
      ->load($id);
    return $simpleMegaMenu;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpleMegaMenuHelper::$entityTypeManager protected property Drupal\Core\Entity\EntityTypeManagerInterface definition.
SimpleMegaMenuHelper::getMegaMenuTypeWhichTargetMenu public function Get SimpleMegaMenuType entities which target a menu. Overrides SimpleMegaMenuHelperInterface::getMegaMenuTypeWhichTargetMenu
SimpleMegaMenuHelper::getSimpleMegaMenu public function Get a SimpleMegaMenu entity. Overrides SimpleMegaMenuHelperInterface::getSimpleMegaMenu
SimpleMegaMenuHelper::getSimpleMegaMenuType public function Get a SimpleMegaMenuType entity. Overrides SimpleMegaMenuHelperInterface::getSimpleMegaMenuType
SimpleMegaMenuHelper::getTargetMenus public function Gets the menus targeted by a specific Simple mega menu type. Overrides SimpleMegaMenuHelperInterface::getTargetMenus
SimpleMegaMenuHelper::menuIsTargetedByMegaMenuType public function Is the menu is referenced by a SimpleMegaMenuType entity. Overrides SimpleMegaMenuHelperInterface::menuIsTargetedByMegaMenuType
SimpleMegaMenuHelper::__construct public function Constructor.