function taxonomy_menu_existing_menu_link_load in Taxonomy menu 8
Loads an existing menu link or creates an initialized one from a taxonomy term.
Parameters
array $term: A taxonomy term to be used to load or create its corresponding menu link.
string $langcode: The language code corresponding to the menu link to be loaded.
Return value
array A menu link corresponding to the taxonomy term.
1 call to taxonomy_menu_existing_menu_link_load()
- 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 211 - Generates menu links for all selected taxonomy terms.
Code
function taxonomy_menu_existing_menu_link_load($term, $langcode) {
$menu_link = array();
// Try to get an existing menu link, else initialize a new one with the right
// settings.
$mlid = _taxonomy_menu_get_mlid($term
->id(), $term
->bundle(), $langcode);
if ($mlid) {
$menu_link = menu_link_load($mlid);
// Flag that we want to update a reference in {taxonomy_menu} table later.
$menu_link['taxonomy_menu']['update'] = TRUE;
}
else {
// Only use the term's weight for menu links to be created, else you will
// reset weights that may have been changed by other processes than
// Taxonomy Menu.
$menu_link = entity_create('menu_link', array(
'module' => 'taxonomy_menu',
'hidden' => 0,
'weight' => $term->weight->value,
'has_children' => 1,
'language' => $langcode,
'taxonomy_menu' => array(
'update' => FALSE,
),
));
}
return $menu_link;
}