You are here

private function MenuTree::displayMenuItem in Taxonomy Facets 7.3

When building menu tree we check if we want to display a menu item depending on various user preferences

Parameters

$term:

$children: s

$tid_selected:

Return value

bool true if to display, false if not to display

1 call to MenuTree::displayMenuItem()
MenuTree::buildMenuTreeRecursively in classes/MenuTree.php

File

classes/MenuTree.php, line 92

Class

MenuTree

Namespace

taxonomyFacets

Code

private function displayMenuItem($term) {
  $display_item = TRUE;
  $filter_applied = FALSE;
  $children = taxonomy_get_children($term->tid, $this->vid);

  // Get user preferences.
  $do_not_display_if_empty = variable_get('taxonomy_facets_display_link_if_empty', FALSE);
  $do_not_display_if_intersection_empty = variable_get('taxonomy_facets_display_link_if_intersection_empty', FALSE);

  // If user preference is to NOT display link if empty, i.e no nodes underneath.
  if ($do_not_display_if_empty) {

    // check if it has nodes underneath
    $has_nodes = taxonomy_facets_get_subnodes($this->vid, $term->tid);
    if (!$has_nodes) {

      // if no nodes do not display
      $display_item = FALSE;
    }
  }

  // User preference is to NOT display link if selection of filters have
  // no nodes underneath.
  if ($do_not_display_if_intersection_empty) {

    // Check if this item is already used as filter applied, if yes we display
    // item anyhow.
    if ($this->tidSelected == $term->tid) {
      $filter_applied = TRUE;
    }

    // Do this check only if item is last leaf
    // and if no filter applied.
    $applied_filters = $this->filtersObject
      ->getAppliedFilters();
    if ($applied_filters && empty($children) && !$filter_applied) {

      // Remove filter from this vocabulary, if any.
      $new_terms_arr = array();
      foreach ($applied_filters as $t) {
        if ($this->vid != $t->vid) {
          $new_terms_arr[] = $t;
        }
      }

      // Add current item to filters.
      $curr_term = new \stdClass();
      $curr_term->tid = $term->tid;
      $new_terms_arr[] = $curr_term;
      $nodes = taxonomy_facets_get_nodes_based_on_intersect_of_terms($new_terms_arr);
      if (empty($nodes)) {
        $display_item = FALSE;
      }
    }
  }
  return $display_item;
}