class SimpleMegaMenuHelper in Simple Mega Menu 8
Same name and namespace in other branches
- 2.0.x src/SimpleMegaMenuHelper.php \Drupal\simple_megamenu\SimpleMegaMenuHelper
Class SimpleMegaMenuHelper.
@package Drupal\simple_megamenu
Hierarchy
- class \Drupal\simple_megamenu\SimpleMegaMenuHelper implements SimpleMegaMenuHelperInterface
Expanded class hierarchy of SimpleMegaMenuHelper
1 string reference to 'SimpleMegaMenuHelper'
1 service uses SimpleMegaMenuHelper
File
- src/
SimpleMegaMenuHelper.php, line 13
Namespace
Drupal\simple_megamenuView 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;
}
}