function multiple_node_menu_save in Multiple Node Menu 7
Helper function to save menu items. Used on hook_node_insert() and hook_node_update().
Parameters
$node: Node object to save menu links for.
2 calls to multiple_node_menu_save()
- multiple_node_menu_node_insert in ./
multiple_node_menu.module - Implements hook_node_insert().
- multiple_node_menu_node_update in ./
multiple_node_menu.module - Implements hook_node_update().
File
- ./
multiple_node_menu.module, line 40 - Add multiple menu management capabilities to node form.
Code
function multiple_node_menu_save($node) {
if (!empty($node->multiple_node_menu_links_deleted)) {
foreach ($node->multiple_node_menu_links_deleted as $deleted_link) {
menu_link_delete($deleted_link);
}
}
if (empty($node->multiple_node_menu_links)) {
return;
}
foreach ($node->multiple_node_menu_links as $delta => &$link) {
if (!empty($link['link_title'])) {
// Set path to node being saved.
$link['link_path'] = "node/{$node->nid}";
// If 'Enabled' checkbox was ticked. Set hidden to FALSE and vice-versa.
if (isset($link['enabled'])) {
$link['hidden'] = (int) (!$link['enabled']);
}
if (!empty($link['description'])) {
$link['options']['attributes']['title'] = $link['description'];
}
else {
unset($link['options']['attributes']['title']);
}
// Add support for i18n_menu and other language aware modules. Set link
// language to node language.
$link['language'] = empty($node->language) ? LANGUAGE_NONE : $node->language;
// Actually save the link.
if (!menu_link_save($link)) {
// @todo Not sure in what situations we should get here, but it doesn't
// look quite right to display error mensages on a loop like this.
drupal_set_message(t('There was an error saving the menu link.'), 'error');
}
}
}
}