You are here

function weight_form_alter in Weight 6

Same name and namespace in other branches
  1. 5 weight.module \weight_form_alter()
  2. 7 weight.module \weight_form_alter()

Implementation of hook_form_alter().

This is where we tweak the admin/content/node to include our weight selector; hide the 'sticky' filter (it won't work when using weight module), and add some help text to the form.

File

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

Code

function weight_form_alter(&$form, $form_state, $form_id) {
  $weight_node_types = variable_get('weight_node_types', array_flip(node_get_types('names')));

  // Node edit page weight selector.
  if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
    $node = $form['#node'];
    if (user_access('assign node weight') || user_access('administer nodes')) {
      if (in_array($node->type, $weight_node_types)) {
        $range = variable_get('weight_range', 20);
        $position = variable_get('weight_position', 0);
        $default = variable_get('weight_default', 0);
        $where = 'weight_form';
        if ($position == 10 && user_access('administer nodes')) {

          // We will add it to the Workflow fieldset.
          $where = 'options';
          $form['options']['#collapsed'] = isset($node->node_weight) ? $node->node_weight == 0 : FALSE;
        }
        else {

          // Add the node weight selector fieldset.
          $form['weight_form'] = array(
            '#type' => 'fieldset',
            '#title' => variable_get('weight_label', t('Node Weight')),
            '#collapsible' => TRUE,
            '#collapsed' => isset($node->node_weight) ? $node->node_weight == 0 : FALSE,
            '#group' => 'additional_settings',
            '#weight' => $position,
          );
        }
        $form[$where]['node_weight'] = array(
          '#type' => 'weight',
          '#title' => t('Weight'),
          '#default_value' => isset($node->node_weight) ? (int) $node->node_weight : $default,
          '#delta' => $range,
          '#description' => t('In a node list context (such as the front page or term pages), list items (e.g. "teasers") will be ordered by "stickiness" then by "node weight" then by "authored on" datestamp. Items with a lower (lighter) node weight value will appear above those with a higher (heavier) value.'),
        );
        if (variable_get('weight_use_menu', FALSE)) {
          $form[$where]['node_weight']['#description'] .= '<br /> ' . t('<strong>Note</strong>: If this node is used in a menu, then this weight will be ignored.');
        }
      }
    }
    else {
      $form['node_weight'] = array(
        '#type' => 'value',
        '#value' => (int) $node->node_weight,
      );
    }
  }
}