You are here

function advanced_menu_form_alter in Advanced Menu 5

Implementation of hook_form_alter().

File

./advanced_menu.module, line 11
Add additional menu options for trees, breadcrumbs, and children.

Code

function advanced_menu_form_alter($form_id, &$form) {
  $item = menu_get_item($form['mid']['#value']);
  if ($form_id == 'menu_edit_item_form') {
    $form['submit']['#weight'] = 5;
    $form['options'] = array(
      '#title' => t('Advanced options'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => ($item['type'] & MENU_VISIBLE_IN_TREE) > 0 && ($item['type'] & MENU_VISIBLE_IN_BREADCRUMB) > 0 && ($item['type'] & MENU_VISIBLE_IF_HAS_CHILDREN) <= 0,
      '#weight' => 1,
      '#tree' => FALSE,
    );

    // move the expanded option into the fieldset
    $form['options']['expanded'] = $form['expanded'];
    unset($form['expanded']);
    $form['options']['tree'] = array(
      '#type' => 'checkbox',
      '#title' => t('Visible in tree views') . (($item['type'] & MENU_VISIBLE_IN_TREE) <= 0 ? ' ' . t('(currently invisible)') : ''),
      '#default_value' => TRUE,
      '#description' => t('Defines whether the menu item should be visible in tree views. (Affects the enabled/disabled option directly)'),
    );
    $form['options']['breadcrumb'] = array(
      '#type' => 'checkbox',
      '#title' => t('Visible in breadcrumbs'),
      '#default_value' => ($item['type'] & MENU_VISIBLE_IN_BREADCRUMB) > 0,
      '#description' => t('Defines whether the menu item should be shown in breadcrumbs.'),
    );
    $form['options']['children'] = array(
      '#type' => 'checkbox',
      '#title' => t('Only visible if it has children'),
      '#default_value' => ($item['type'] & MENU_VISIBLE_IF_HAS_CHILDREN) > 0,
      '#description' => t('Defines whether the menu item should be visible if it doesn\'t have any children.'),
    );
    $form['#validate'] = array(
      'advanced_menu_edit_item_form_validate' => array(),
    );
  }
}