You are here

function taxonomy_menu_menu_link_save in Taxonomy menu 8

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

Saves a menu link in a menu, based on a taxonomy term.

Parameters

$term: A taxonomy term used to save a respective menu item.

$menu_name: The machine name of the menu in which the menu link should be saved.

Return value

The menu link ID of the menu item that has been saved. FALSE, if no item could be saved.

2 calls to taxonomy_menu_menu_link_save()
_taxonomy_menu_save_menu_links_process in ./taxonomy_menu.batch.inc
Processes the batch.
_taxonomy_menu_termapi_helper in ./taxonomy_menu.module
Abstraction of hook_termapi_<op>().

File

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

Code

function taxonomy_menu_menu_link_save($term, $menu_name) {
  $mlid = FALSE;

  // Prepare a menu link based on the settings of the vocabulary edit page and
  // save it.
  $menu_link = taxonomy_menu_menu_link_prepare($term, $menu_name);
  drupal_alter('taxonomy_menu_link', $menu_link, $term, $menu_name);
  if (menu_link_save($menu_link)) {
    $mlid = entity_load_by_uuid('menu_link', $menu_link->uuid)->mlid;

    // Let other modules perform actions after the menu item has been saved.
    foreach (\Drupal::moduleHandler()
      ->getImplementations('taxonomy_menu_save') as $module) {
      $function = $module . '_taxonomy_menu_save';
      $function($term, $menu_link, $mlid);
    }
  }
  return $mlid;
}