You are here

function advanced_menu_menu_admin_form_alter in Advanced Menu 6.x

Same name and namespace in other branches
  1. 7 menu_admin/advanced_menu_menu_admin.module \advanced_menu_menu_admin_form_alter()

Implementation of hook_form_alter().

File

menu_admin/advanced_menu_menu_admin.module, line 12
Provides advanced menu permissioning.

Code

function advanced_menu_menu_admin_form_alter(&$form, $form_state, $form_id) {
  $menu = $form;
  switch ($form_id) {
    case 'menu_edit_menu':
      if (user_access('administer advanced menu permissions')) {
        $form['submit']['#weight'] = 2;
        $form['roles'] = array(
          '#type' => 'checkboxes',
          '#title' => t('Editors'),
          '#default_value' => _advanced_menu_menu_admin_roles($menu),
          '#options' => user_roles(TRUE),
          '#description' => t('Roles that are checked will be able to administer this menu.'),
          '#weight' => 1,
        );
        $form['#submit'][] = 'advanced_menu_menu_admin_form_submit';
      }
      break;
    case 'menu_edit_item':

      // Generate a list of possible parents (not including this item or descendants).
      $menus = menu_get_menus();
      if (!user_access('administer menu')) {
        $menus = _advanced_menu_menu_admin_menus($menus);
      }
      $item = $form['menu']['#item'] ? $form['menu']['#item'] : menu_load($form['menu']['original_item']['#value']['menu_name']);
      $options = menu_parent_options($menus, $item);
      $default = $item['menu_name'] . ':' . (isset($item['plid']) ? $item['plid'] : 0);
      if (!isset($options[$default])) {
        $default = 'navigation:0';
      }
      $form['menu']['parent'] = array(
        '#type' => 'select',
        '#title' => t('Parent item'),
        '#default_value' => $default,
        '#options' => $options,
        '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth. Some menu items may not be available as parents if selecting them would exceed this limit.', array(
          '!maxdepth' => MENU_MAX_DEPTH,
        )),
        '#attributes' => array(
          'class' => 'menu-title-select',
        ),
      );
      $form['submit']['#weight'] = 2;
      $form['#submit'][] = 'advanced_menu_menu_admin_form_submit';
      break;
    default:
      if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
        $form['menu'] = array(
          '#type' => 'fieldset',
          '#title' => t('Menu settings'),
          '#access' => advanced_menu_core_access('administer menu', 'edit node'),
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
          '#tree' => TRUE,
          '#weight' => -2,
          '#attributes' => array(
            'class' => 'menu-item-form',
          ),
        );
        $item = $form['#node']->menu;
        if ($item['mlid']) {

          // There is an existing link.
          $form['menu']['delete'] = array(
            '#type' => 'checkbox',
            '#title' => t('Delete this menu item.'),
          );
        }
        if (!$item['link_title']) {
          $form['menu']['#collapsed'] = TRUE;
        }
        foreach (array(
          'mlid',
          'module',
          'hidden',
          'has_children',
          'customized',
          'options',
          'expanded',
          'hidden',
          'parent_depth_limit',
        ) as $key) {
          $form['menu'][$key] = array(
            '#type' => 'value',
            '#value' => $item[$key],
          );
        }
        $form['menu']['#item'] = $item;
        $form['menu']['link_title'] = array(
          '#type' => 'textfield',
          '#title' => t('Menu link title'),
          '#default_value' => $item['link_title'],
          '#description' => t('The link text corresponding to this item that should appear in the menu. Leave blank if you do not wish to add this post to the menu.'),
          '#required' => FALSE,
        );

        // Generate a list of possible parents (not including this item or descendants).
        $menus = menu_get_menus();
        if (!user_access('administer menu')) {
          $menus = _advanced_menu_menu_admin_menus($menus);
        }
        $options = menu_parent_options($menus, $item);
        $default = $item['menu_name'] . ':' . $item['plid'];
        if (!isset($options[$default])) {
          $default = 'primary-links:0';
        }
        $form['menu']['parent'] = array(
          '#type' => 'select',
          '#title' => t('Parent item'),
          '#default_value' => $default,
          '#options' => $options,
          '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth. Some menu items may not be available as parents if selecting them would exceed this limit.', array(
            '!maxdepth' => MENU_MAX_DEPTH,
          )),
          '#attributes' => array(
            'class' => 'menu-title-select',
          ),
        );
        $form['#submit'][] = 'menu_node_form_submit';
        $form['menu']['weight'] = array(
          '#type' => 'weight',
          '#title' => t('Weight'),
          '#delta' => 50,
          '#default_value' => $item['weight'],
          '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
        );
      }
      break;
  }
}