menu_helper_redirect_form_menu_edit_item_alter

custom/menu_helper/menu_helper_redirect/menu_helper_redirect.module, line 157

Versions
6
menu_helper_redirect_form_menu_edit_item_alter(&$form, $form_state)

Implementation of hook_form_FORM_ID_alter().

See also

menu_helper_redirect_form_menu_edit_item_alter_submit()

@see menu_helper_redirect_form_menu_edit_item_alter_submit_post()

Code

<?php
function menu_helper_redirect_form_menu_edit_item_alter(&$form, $form_state) {
  // Remove redirect from link path
  $link_path = $form['menu']['link_path']['#default_value'];
  if (strpos($link_path, 'redirect/') === 0) {
    $menu_helper_redirect = 1;
    $form['menu']['link_path']['#default_value'] = preg_replace('/redirect\//', '', $link_path);
  }
  else {
    $menu_helper_redirect = 0;
  }

  // Remove mlid from first-child path since end user don't need to see it.
  if (strpos($link_path, 'first-child/') === 0) {
    $form['menu']['link_path']['#default_value'] = 'first-child';
  }

  // Add first-child description to link_path
  $form['menu']['link_path']['#description'] .= ''. t("Enter '%first_child' to be redirect to this menu item's first child.", array('%first_child' => 'first-child'));

  // Set weights
  _menu_helper_redirect_set_form_weights($form);

  // Get the expanded checkboxes weight
  $form['menu']['menu_helper_redirect'] = array(
    '#type' => 'checkbox',
    '#title' => t('Redirect'),
    '#description' => t('If selected this menu item will never appear in the active menu trail.'),
    '#default_value' => $menu_helper_redirect,
    '#weight' => $form['menu']['expanded']['#weight'], // Position after expanded checkbox
  );

  // Wrap the submit handler with pre and post submission handlers
  $form['#submit'] = array_merge(array('_menu_helper_redirect_form_menu_edit_item_alter_pre_submit'), $form['#submit'], array('_menu_helper_redirect_form_menu_edit_item_alter_post_submit'));
}
?>