You are here

function weight_node_presave in Weight 7

Implements hook_node_presave().

File

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

Code

function weight_node_presave($node) {
  $weight_node_types = variable_get('weight_node_types', array_flip(node_type_get_names()));
  if (in_array($node->type, $weight_node_types)) {

    // Non-weighted nodes have a weight of zero.
    if (is_null($node->node_weight)) {
      $node->node_weight = variable_get('weight_default', 0);
    }

    // If the admin wants to use the menu weight, see if there is one.
    if (variable_get('weight_use_menu', FALSE)) {
      $node->node_weight = isset($node->menu['link_title']) && !empty($node->menu['link_title']) ? $node->menu['weight'] : $node->node_weight;
    }

    // Encode weight into the sticky value for the database.
    _weight_encode($node);
  }
}