You are here

function weight_form_node_admin_content_alter in Weight 7.2

Same name and namespace in other branches
  1. 6 weight.module \weight_form_node_admin_content_alter()

Implements hook_form_FORM_ID_alter().

File

./weight.module, line 153

Code

function weight_form_node_admin_content_alter(&$form, &$form_state) {
  if (user_access('assign node weight')) {
    $weight_types = _weight_get_types();
    $add_column = FALSE;
    if (!empty($form['admin']['nodes']['#options'])) {
      $nodes = $form['admin']['nodes']['#options'];
    }
    elseif (!empty($form['admin']['nodes']['#rows'])) {
      $nodes = $form['admin']['nodes']['#rows'];
    }
    else {
      $nodes = array();
    }
    foreach ($nodes as $nid => $node) {
      $node = node_load($nid);
      if (in_array($node->type, $weight_types)) {
        $settings = _weight_get_settings($node->type);
        if (!$settings['menu_weight']) {
          $options = _weight_get_options($settings['range']);
          $form['weight'][$nid] = array(
            '#type' => 'select',
            '#options' => $options,
            '#default_value' => isset($node->weight_weight) ? $node->weight_weight : $settings['default'],
            '#ajax' => array(
              'callback' => '_weight_set_ajax',
            ),
          );
          $add_column = TRUE;
        }
        else {
          $form['weight'][$nid] = array(
            '#value' => '',
          );
        }
      }
      else {
        $form['weight'][$nid] = array(
          '#value' => '',
        );
      }
    }
    $form['weight']['#add_column'] = $add_column;
    $form['#after_build'][] = 'weight_node_admin';
  }
}