menu_node_edit_node_form_alter

Versions
menu_node_edit
menu_node_edit_node_form_alter(&$form, $form_state)

Form alter for node forms.

Code

./menu_node_edit.module, line 457

<?php
function menu_node_edit_node_form_alter(&$form, $form_state) {
  global $user;
  // Let the administrator change the menu visibility.
  if (user_access('administer menu')) {
    $form['menu']['hidden'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hidden'),
      '#default_value' => $form['menu']['hidden']['#value'],
      '#weight' => 5,
      '#description' => t('Hidden items will not be listed in site navigation, but they still appear as section content.'),
    );
  }
  // If the user can administer menus, then we do nothing else.
  // Likewise, if the user cannot publish to sections, then return.
  if (user_access('administer menu') || !user_access('publish to my sections')) {
    return;
  }
  // Check to see if we care about this node type.
  $type = $form['#node']->type;
  $allowed = menu_node_edit_variable('node_types');
  if (empty($allowed[$type])) {
    return;
  }
  // Check the user permissions.
  $account = $user;
  $account->menu_node_edit = menu_node_edit_load_access($account);
  // If this value is empty, we cannot do anything.
  if (empty($account->menu_node_edit)) {
    return;
  }
  $items = array();
  $check = array();
  foreach ($account->menu_node_edit as $mlid) {
    $item = db_fetch_object(db_query("SELECT mlid, menu_name, depth FROM {menu_links} WHERE mlid = %d", $mlid));
    $result = db_query("SELECT mlid, menu_name FROM {menu_links} WHERE %s= %d", "p$item->depth", $item->mlid);
    while ($data = db_fetch_object($result)) {
      $items[$data->menu_name][] = $data->mlid;
      $check[] = $data->mlid;
    }
  }
  if (empty($items)) {
    return;
  }
  // If the item is assigned to a different menu, do nothing.
  $default = 0;
  if (!empty($form['#node']->menu['mlid'])) {
    $default = $form['#node']->menu['mlid'];
  }
  if (!empty($default) && !in_array($default, $check)) {
    return;
  }
  // Allow values passed via $_GET.
  if (empty($default) && isset($_GET['section']) && in_array($_GET['section'], $check)) {
    $default = $_GET['section'];
  }
  $names = menu_get_menus();
  foreach ($items as $menu => $filter) {
    $options[$names[$menu]] = menu_node_tree(menu_tree_all_data($menu), NULL, $filter);
  }
  // Prepare the options for the form.
  ksort($options);  
  // Set the proper help text.
  $collapsed = FALSE;
  if (empty($form['menu']['mlid']['#value'])) {
    // On node creation, editors with limited permissions may choose not to create a menu item.
    $options = array_merge(array(0 => t('Do not assign to a section')), $options);
    $description = t('This content has not been assigned to a section. Select the parent item for this new content.');
  }
  else if ($default == $form['menu']['mlid']['#value']) {
    // However, once created, only an administrator can remove a menu item.
    $description = t('This content has been assigned to a section. You may change the selection below to move it to a new section.');
    $collapsed = TRUE;
  }
  $form['menu_node_edit'] = array(
    '#type' => 'fieldset',
    '#title' => t('Section'),
    '#description' => $description,
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#weight' => module_exists('content') ? content_extra_field_weight($form['type']['#value'], 'menu_node_edit') : -1,
  );
  $form['menu_node_edit']['mlid'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $default,
  );
  if (user_access('set menu visibility')) {
    $form['menu_node_edit']['hidden'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hidden'),
      '#default_value' => $form['menu']['hidden']['#value'],
      '#description' => t('Hidden items will not be listed in site navigation, but they still appear as section content.'),
    );
  }
  $form['#submit'][] = 'menu_node_edit_node_form_submit';
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List