You are here

function taxonomy_facets_build_url_alias in Taxonomy Facets 7.2

Build a URL to be used in the menu item.

Use the taxonomy term of the menu item that we are building, plus all other terms in the page url to construct the url of the menu item.

Parameters

integer $vid: Vocabulary id.

array $terms: Terms in the url, i.e applied filters

integer $tid: Term id of the term, the term of the menu item that we are building.

Return value

string Menu item url.

2 calls to taxonomy_facets_build_url_alias()
taxonomy_facets_get_menu_tree in ./taxonomy_facets.module
Print out menu tree for each vocab selected to be taxo faceted filter.
_taxonomy_facets_get_menu_tree in ./taxonomy_facets.module
Helper function for taxonomy_facets_get_menu_tree.

File

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

Code

function taxonomy_facets_build_url_alias($vid, $terms, $tid) {
  global $base_url;

  // Get the first argument form settings and prepend language prefix
  $alias = $base_url . taxonomy_facets_prepend_language_prefix() . '/' . variable_get('taxonomy_facets_first_argument', 'items_list');
  $filters_vids = array();

  // If no other terms applied as filters yet, i.e no filters selected
  // then just build url based on the term we are building menu item for.
  if ($terms == NULL) {
    $alias .= '/' . taxonomy_facets_get_term_url_alias_from_tid($tid);
  }
  else {

    // There are other terms, so we need to append other filter terms to the
    // current menu item, but always preserving the order of vocabularies,
    // so that we do not end up with multiple urls for the same page.
    // So replace current vocabulary filter item with the url
    // of the current menu item we are printing.
    $count = 0;
    $arr_element = 999999;
    foreach ($terms as $term) {

      // If filter is from current vocab do not append it,
      // as we are using menu item in loop to build urls alias for this vocab bit.
      if ($term['vid'] == $vid) {

        // Get index of array element.
        $arr_element = $count;
      }
      $count++;
      $filters_vids[] = $term['vid'];
    }

    // Found, so replace.
    if ($arr_element != 999999) {
      $terms[$arr_element]['term_path_alias'] = taxonomy_facets_get_term_url_alias_from_tid($tid);
    }
    else {

      // There was no term in current filters that was part of this vocabulary
      // (vocabulary we are building tree for)
      // so create term for it as we will need it to build menu item, it
      // will be the term of the menu item we are building.
      $term['tid'] = $tid;
      $term['term_path_alias'] = taxonomy_facets_get_term_url_alias_from_tid($tid);
      $term['term_name'] = 'x';
      $term['vid'] = $vid;
      $terms[] = $term;
      $filters_vids[] = $vid;
    }

    // If more than one filter order them.
    if (count($terms) > 1) {

      // Get order of filters from user preferences,
      // this is a variable that stores vocabularies to be used for
      // taxo faceted navigation, and its ordered.
      $taxos = variable_get('taxonomy_facets_taxonomies', $terms);

      // Will hold ordered filters.
      $ret_filters = array();
      foreach ($taxos as $taxo) {

        // If this vocab in loop is also in the filter array($terms) , add
        // it to new array of filters,
        // that way filters in this new array will be ordered the same as in
        // user preference array ($taxos).
        if (in_array($taxo['vid'], $filters_vids)) {
          $ret_filters[] = taxonomy_facets_get_array_element($taxo['vid'], $terms);
        }
      }
    }
    else {
      $ret_filters = $terms;
    }

    // Build menu item url string.
    foreach ($ret_filters as $term) {
      if ($term['term_path_alias']) {
        $alias .= '/' . $term['term_path_alias'];
      }
    }
  }
  return $alias;
}