You are here

private function MenuTree::buildMenuTreeRecursively in Taxonomy Facets 8

1 call to MenuTree::buildMenuTreeRecursively()
MenuTree::__construct in src/MenuTree.php

File

src/MenuTree.php, line 33

Class

MenuTree

Namespace

Drupal\taxonomy_facets

Code

private function buildMenuTreeRecursively($parent) {
  $tree = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadTree($this->vid, $parent, 1);
  $begin_ul = [
    '#theme' => 'taxonomy_facets_ul_wrapper_begin_template',
    '#menuClass' => $this->menu_class,
    '#attached' => [
      'library' => [
        'taxonomy_facets/change_links',
      ],
    ],
  ];

  // Only first time we call this function the menu class is cleclearfix, than we set it to null,
  // as sub <ul> css class should be only menu, not clearfix menu
  $this->menu_class = NULL;
  $this->menuTree[] = render($begin_ul);
  foreach ($tree as $leaf) {

    // @todo if($this->displayMenuItem($leaf)){
    if (true) {
      $menuItemInChildrenLeafs = $this
        ->menuItemInChildrenLeafs($leaf->tid);
      $leafCssClass = $this
        ->calculateItemCssClass($menuItemInChildrenLeafs, $leaf->tid);
      $leaf = new MenuLeaf($leaf, $leafCssClass);
      $this->menuTree[] = [
        '#theme' => 'taxonomy_facets_menu_leaf_template',
        '#menuLeaf' => $leaf,
      ];
      if ($menuItemInChildrenLeafs || $this
        ->menuItemIsFilterApplied($leaf->tid)) {
        $this
          ->buildMenuTreeRecursively($leaf->tid);
      }
    }
  }
  $end_ul = [
    '#theme' => 'taxonomy_facets_ul_wrapper_end_template',
  ];
  $this->menuTree[] = render($end_ul);
}