You are here

function taxonomy_menu_term_get_plid in Taxonomy menu 8

Same name and namespace in other branches
  1. 7.2 taxonomy_menu.module \taxonomy_menu_term_get_plid()

Helper function to determine a parent mlid for a specific taxonomy term, in function of the settings of the administration pages.

Parameters

$term: The term, which we want to find the parent mlid.

$langcode: The language of the term.

Return value

$plid The corresponding parent mlid.

1 call to taxonomy_menu_term_get_plid()
taxonomy_menu_menu_link_prepare in ./taxonomy_menu.module
Prepares a taxonomy item to be saved as a menu link.

File

./taxonomy_menu.module, line 251
Generates menu links for all selected taxonomy terms.

Code

function taxonomy_menu_term_get_plid($term, $langcode) {
  $plid = 0;
  $parents = taxonomy_term_load_parents($term
    ->id());
  if (empty($parents)) {

    // Try to get the vocabulary parent from the settings
    // Returns for example:
    //  - "0:0" : DISABLED
    //  - "main-menu:0" : MENU ROOT
    //  - "main-menu:123" : MENU ITEM ROOT
    $vocab_parent = taxonomy_menu_variable_get('vocab_parent', $term
      ->bundle(), NULL);
    if ($vocab_parent) {

      // "main-menu:123" case
      $plid = $vocab_parent;
    }
    else {

      // "main-menu:0" OR "0:0" cases
      $plid = 0;
    }
  }
  else {

    // We have parents for this taxonomy term. Only get the first one, we don't
    // support multiple parents yet.
    // @TODO Support multiple parents.
    foreach ($parents as $parent) {
      $plid = _taxonomy_menu_get_mlid($parent
        ->id(), $term
        ->bundle(), $langcode);
      break;
    }
    if ($plid == FALSE) {
      $plid = 0;
    }
  }
  return $plid;
}