SimpleMegaMenuHelper.php in Simple Mega Menu 8
File
src/SimpleMegaMenuHelper.php
View source
<?php
namespace Drupal\simple_megamenu;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\simple_megamenu\Entity\SimpleMegaMenuTypeInterface;
class SimpleMegaMenuHelper implements SimpleMegaMenuHelperInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function getTargetMenus(SimpleMegaMenuTypeInterface $entity) {
return array_filter($entity
->getTargetMenu());
}
public function getMegaMenuTypeWhichTargetMenu($menu_name) {
$mega_menu_types = [];
$simple_mega_menu_types = $this->entityTypeManager
->getStorage('simple_mega_menu_type')
->loadMultiple();
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;
}
public function menuIsTargetedByMegaMenuType($menu_name) {
$simple_mega_menu_types = $this->entityTypeManager
->getStorage('simple_mega_menu_type')
->loadMultiple();
foreach ($simple_mega_menu_types as $entity) {
$target_menus = $this
->getTargetMenus($entity);
if (in_array($menu_name, $target_menus)) {
return TRUE;
}
}
return FALSE;
}
public function getSimpleMegaMenuType($id) {
$simpleMegaMenuType = $this->entityTypeManager
->getStorage('simple_mega_menu_type')
->load($id);
return $simpleMegaMenuType;
}
public function getSimpleMegaMenu($id) {
$simpleMegaMenu = $this->entityTypeManager
->getStorage('simple_mega_menu')
->load($id);
return $simpleMegaMenu;
}
}