You are here

function _ack_menu_form_alter in Access Control Kit 7

Helper function for altering the menu item and node forms.

Parameters

array &$form: A form structure representing a menu item. Must have 'parent' and 'weight' element children.

array &$form_state: The form state. If 'ack_menu' is already defined in the array, it must contain 'schemes' and 'realms' values, defining (respectively) the schemes that can manage the link and the realms that the user can assign to it.

string $form_id: The form identifier.

array $link: The menu link represented by the form.

See also

ack_menu_form_menu_edit_item_alter()

ack_menu_form_node_form_alter()

2 calls to _ack_menu_form_alter()
ack_menu_form_menu_edit_item_alter in ack_menu/ack_menu.module
Implements hook_form_FORM_ID_alter().
ack_menu_form_node_form_alter in ack_menu/ack_menu.module
Implements hook_form_BASE_FORM_ID_alter().

File

ack_menu/ack_menu.module, line 400
The ACK menu module.

Code

function _ack_menu_form_alter(&$form, &$form_state, $form_id, $link) {

  // Place ack_menu values in the form state for use by the handlers.
  if (!isset($form_state['ack_menu'])) {
    $form_state['ack_menu'] = array(
      'schemes' => access_object_schemes('menu_link'),
      'realms' => _ack_menu_user_realms(),
    );
  }
  $form_state['ack_menu']['admin'] = user_access('administer ack_menu');
  $form_state['ack_menu']['global admin'] = user_access('administer menu');
  $schemes = $form_state['ack_menu']['schemes'];
  $realms = $form_state['ack_menu']['realms'];

  // Apply AckMenuHandlerInterface::objectFormAlter() for all schemes.
  foreach ($schemes as $scheme) {

    // A new link can be added to any allowed realm, and admins can change the
    // realm assignments of existing links.
    if (empty($link['mlid']) || $form_state['ack_menu']['admin']) {
      $scheme_realms = isset($realms[$scheme->machine_name]) ? $realms[$scheme->machine_name] : array();
    }
    else {

      // For non-admins, an existing link must stay in its current realm.
      $scheme_realms = NULL;
    }
    $scheme->handlers['menu_link']
      ->objectFormAlter('menu_link', $link, $form, $form_state, $form_id, $scheme_realms);
  }

  // If this link's current parent is not manageable by the user, then the user
  // should not be able to change this link's position, since that would
  // effectively be rearranging the parent's menu tree.
  if (!empty($link['mlid']) && !empty($link['plid'])) {
    $parent = menu_link_load($link['plid']);
    if (!empty($parent)) {
      $form['weight']['#disabled'] = !ack_menu_link_access($parent);
    }
  }
}