You are here

public static function CheeseburgerMenuItem::createFromMenuLinkTreeElement in Cheeseburger Menu 5.0.x

Creates cheeseburger menu item from menu link tree.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement $menu_link_tree_element: Menu link tree element to create from.

bool $menu_item_settings: @see \Drupal\cheeseburger_menu\CheeseburgerMenuItem::applySettings()

Return value

static Created cheeseburger menu item.

1 call to CheeseburgerMenuItem::createFromMenuLinkTreeElement()
CheeseburgerMenuService::buildMenu in src/CheeseburgerMenuService.php
Returns cheeseburger menu from menu.

File

src/CheeseburgerMenuItem.php, line 114

Class

CheeseburgerMenuItem
Cheeseburger menu item class.

Namespace

Drupal\cheeseburger_menu

Code

public static function createFromMenuLinkTreeElement(MenuLinkTreeElement $menu_link_tree_element, $menu_item_settings = []) {
  $attribute = new Attribute([
    'class' => [
      'menu-link',
      'cheeseburger-menu__item',
      Html::cleanCssIdentifier($menu_link_tree_element->link
        ->getMenuName()) . '__item',
    ],
  ]);
  $menu_link_item_instance = new static($menu_link_tree_element->link
    ->getTitle(), $menu_link_tree_element->link
    ->getUrlObject(), $attribute);
  foreach ($menu_link_tree_element->subtree as $subtree_menu_link_tree_element) {
    if ((!$subtree_menu_link_tree_element->access instanceof AccessResultInterface || $subtree_menu_link_tree_element->access
      ->isAllowed()) && $subtree_menu_link_tree_element->link
      ->isEnabled()) {
      $menu_link_item_instance
        ->addChild(self::createFromMenuLinkTreeElement($subtree_menu_link_tree_element, $menu_item_settings));
    }
  }
  $menu_link_item_instance
    ->applySettings($menu_item_settings)
    ->setOriginalEntityTypeId($menu_link_tree_element->link
    ->getBaseId())
    ->setOriginalEntityId($menu_link_tree_element->link
    ->getPluginId());
  if ($menu_link_tree_element->inActiveTrail) {
    $menu_link_item_instance
      ->setIsInActiveTrail();
  }
  return $menu_link_item_instance;
}