You are here

function weight_form_node_admin_content_alter in Weight 6

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

Implementation of hook_form_FORM_ID_alter().

File

./weight.module, line 220
This module uses the sticky column of the node table to add weighting to nodes.

Code

function weight_form_node_admin_content_alter(&$form, $form_state) {
  if (!variable_get('weight_content_admin', FALSE)) {
    return;
  }
  $weight_node_types = variable_get('weight_node_types', array_flip(node_get_types('names')));
  $weight_node_type_names = array();
  foreach ($weight_node_types as $type) {
    $weight_node_type_names[] = node_get_types('name', $type);
  }
  $weight_range = variable_get('weight_range', 20);
  $weights = array();
  for ($i = -$weight_range; $i <= $weight_range; ++$i) {
    $weights[$i] = $i;
  }
  $form['admin']['weight']['#tree'] = TRUE;
  foreach ($form['admin']['title'] as $nid => $value) {
    $one_of_ours = in_array($form['admin']['name'][$nid]['#value'], $weight_node_type_names);
    if ($one_of_ours) {

      // Get more stuff about the node.
      $node = db_fetch_object(db_query("SELECT nid, status, sticky, promote, translate, moderate FROM {node} WHERE nid = %d", $nid));

      // Convert to our weight range.
      _weight_decode($node);
      $weight = $node->node_weight;
      $form['admin']['weight'][$nid] = array(
        '#type' => 'select',
        '#options' => $weights,
        '#default_value' => $weight,
        '#ahah' => array(
          'path' => 'admin/node/weight/_weight_change/' . $nid,
          'event' => 'change',
        ),
      );
      $status = $node->status ? t('published') : t('not published');
      $status .= $node->sticky ? '<br />' . t('sticky') : NULL;
      $status .= $node->promote ? '<br />' . t('promoted') : NULL;
      $status .= $node->translate ? '<br />' . t('translate') : NULL;
      $status .= $node->moderate ? '<br />' . t('moderated') : NULL;
      $form['admin']['status'][$nid]['#value'] = $status;
    }
    else {
      $form['admin']['weight'][$nid]['#value'] = '';
    }
  }
}