You are here

function _weight_change in Weight 6

Same name and namespace in other branches
  1. 7 weight.module \_weight_change()

Ajax callback for weight manager page.

1 string reference to '_weight_change'
weight_menu in ./weight.module
Implementation of hook_menu().

File

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

Code

function _weight_change($nid) {
  $form_state = array(
    'storage' => NULL,
    'rebuild' => TRUE,
  );
  $form_build_id = $_POST['form_build_id'];
  include_once 'modules/node/node.admin.inc';

  // Step #4.
  $form = form_get_cache($form_build_id, $form_state);

  // Preparing for #5.
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;

  // Step #5.
  drupal_process_form($form_id, $form, $form_state);

  // Step #6 and #7 and #8.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Doing it this way preserves the revision information.
  $node = node_load($nid);
  $node->node_weight = $form_state['post']['weight'][$nid];
  node_save($node);
  $output = $form_state['post']['weight'][$nid];

  // Final rendering callback.
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}