You are here

function taxonomy_facets_display_meny_item_check in Taxonomy Facets 7.2

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 taxonomy_facets_display_meny_item_check()
_taxonomy_facets_get_menu_tree in ./taxonomy_facets.module
Helper function for taxonomy_facets_get_menu_tree.

File

./taxonomy_facets.module, line 596
Taxo Faceted Navigation module code.

Code

function taxonomy_facets_display_meny_item_check($vid, $term, $children, $terms, $tid_selected) {
  $display_item = TRUE;
  $filter_applied = FALSE;

  // 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($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 ($tid_selected == $term->tid) {
      $filter_applied = TRUE;
    }

    // Do this check only if item is last leaf
    // and if no filter applied.
    if ($terms && empty($children) && !$filter_applied) {

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

      // Add current item to filters.
      $curr_term['tid'] = $term->tid;
      $curr_term['term_path_alias'] = '';
      $curr_term['term_name'] = '';
      $curr_term['vid'] = '';
      $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;
}