function menu_link_weight_node_form_submit in Menu Link Weight 7
Same name and namespace in other branches
- 8.2 menu_link_weight.node.inc \menu_link_weight_node_form_submit()
- 8 menu_link_weight.node.inc \menu_link_weight_node_form_submit()
Custom submit hook for node form which reorders menu link weights.
Note: this wil not reorder links that the current user does not have access to (ie. links to access-controlled nodes).
1 string reference to 'menu_link_weight_node_form_submit'
- menu_link_weight_form_node_form_alter in ./
menu_link_weight.module - Implements hook_form_FORM_ID_alter().
File
- ./
menu_link_weight.module, line 409 - Replaces the menu link weight dropdown with a tabledrag widget.
Code
function menu_link_weight_node_form_submit($form, &$form_state) {
// For graceful JS degradation.
if ($form_state['triggering_element']['#value'] == menu_link_weight_get_button_text()) {
$form_state['values']['menu']['parent'] = $form_state['input']['menu']['parent'];
$form_state['rebuild'] = TRUE;
return;
}
// Return on empty submissions or if if 'Provide a menu link' not selected.
if (!isset($form_state['values']['menu']['menu_link_weight']) || !$form_state['values']['menu']['enabled']) {
return;
}
$transaction = db_transaction();
try {
// Because the form elements were keyed with the item ids from the database,
// we can simply iterate through the submitted values.
foreach ($form_state['values']['menu']['menu_link_weight'] as $mlid => $info) {
if ($mlid == 'link_current') {
// Do nothing. Changing the weight of the current link will be handled
// in hook_node_submit() instead.
continue;
}
$link = menu_link_load($mlid);
$link['weight'] = $info['weight'];
menu_link_save($link);
}
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('menu_link_weight', $e);
}
}