You are here

function advanced_menu_submenu_form_alter in Advanced Menu 7

Implementation of hook_form_alter().

File

submenu/advanced_menu_submenu.module, line 46
Provides advanced menu submenus.

Code

function advanced_menu_submenu_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'menu_edit_item':
      $url_comp = explode('/', request_path());
      $url_action = array_pop($url_comp);
      $url_menu = array_pop($url_comp);
      $default_value = NULL;
      if ($url_action == 'add-submenu' || substr($form['link_path']['#default_value'], 0, 24) == "advanced-menus/sub-menus") {
        if (substr($form['link_path']['#default_value'], 0, 24) == "advanced-menus/sub-menus") {
          $url_menu = $form['original_item']['#value']['menu_name'];
          $default_value = $form['link_path']['#default_value'];
        }
        $form['link_title'] = array(
          '#type' => 'hidden',
          '#value' => 'Sub-Menu',
          '#required' => FALSE,
        );
        $menus = _advanced_menu_submenu_menus($url_menu, $default_value);
        $options = array();
        foreach ($menus as $key => $value) {
          $options['advanced-menus/sub-menus/' . $key] = $value;
        }
        $form['link_path'] = array(
          '#type' => 'select',
          '#title' => t('Sub Menu'),
          '#options' => $options,
          '#description' => t('The menu to include as a sub menu.'),
          '#attributes' => array(
            'class' => array(
              'menu-title-select',
            ),
          ),
        );
        if (!empty($default_value)) {
          $form['link_path']['#default_value'] = $default_value;
        }
        $form['description'] = array(
          '#type' => 'hidden',
        );
        $form['expanded'] = array(
          '#type' => 'hidden',
          '#value' => 0,
        );
      }
      break;
  }
}