Commit abf63346 authored by Harry Slaughter's avatar Harry Slaughter

added help text, documentation, cleaned up code a bit

parent 4dcf61e3
......@@ -3,14 +3,17 @@
by Jeff Robbins ::: jeff /@t\ jjeff /d0t\ com
*******************************************************
This module adds a weight option to enabled node types.
It uses the node table's 'sticky' column to store
weights as well as sticky information (so that feature
is not lost). Nodes with lower weight will float to the
top of lists, while heavier items will sink.
This module adds a weight option to enabled node types. It uses the node table's
'sticky' column to store weights as well as sticky information (so that feature
is not lost). Nodes with lower weight will float to the top of lists, while
heavier items will sink.
This is useful for sorting non-cronological nodes like
bios or ecommerce products.
This is useful for sorting non-cronological nodes like bios or ecommerce
products.
Nodes will be sorted first by stickiness, then by
weight, then by creation date.
\ No newline at end of file
Nodes will be sorted first by stickiness, then by weight, then by creation date.
NOTE: There is currently a known issue in which they 'sticky' state is not
properly interpreted on the 'content' (admin/node) page once nodes have had
their sticky flag converted to the format required by the weight module.
However, this does not affect the presentation of sticky and non-sticky nodes.
......@@ -40,7 +40,16 @@ function weight_help($section) {
However, enabling 'assign node weight' will allow non-node-admin users
to adjust weight on their own nodes. Find these settings <a
href='%access'>here</a>.</p>
", array('%settings' => url('admin/settings/weight/setup'), '%access' => url('admin/access')));
<p><strong>Bulk weight management:</strong> You may easily manage the
weight of multiple nodes simultaneously by using the <a href='%weight_manager'>
node weight manager</a>.</p>
", array(
'%settings' => url('admin/settings/weight/setup'),
'%access' => url('admin/access'),
'%weight_manager' => url('admin/node/weight')
)
);
}
}
......@@ -58,30 +67,62 @@ function weight_menu($may_cache){
// bulk manage node weights
$items[] = array(
'path' => 'admin/node/weight',
'title' => t('node weights'),
'path' => 'admin/node/weight',
'title' => t('node weights'),
'callback' => 'weight_manager',
'access' => user_access('administer nodes'),
'type' => MENU_LOCAL_TASK,
'weight' => -1
'access' => user_access('administer nodes'),
'type' => MENU_LOCAL_TASK,
'weight' => -1
);
// ajax callback for weight manager page
$items[] = array(
'path' => 'admin/node/weight/_change_weight',
'path' => 'admin/node/weight/_change_weight',
'callback' => '_change_weight',
'access' => user_access('administer nodes'),
'type' => MENU_CALLBACK
'access' => user_access('administer nodes'),
'type' => MENU_CALLBACK
);
// top level settings
$items[] = array('title' => t('weight'), 'path' => 'admin/settings/weight', 'access' => $access, 'callback'=>'weight_settings_page');
$items[] = array(
'title' => t('weight'),
'path' => 'admin/settings/weight',
'access' => $access,
'callback' =>'weight_settings_page'
);
// 2nd level nav (tabs)
$items[] = array('title' => t('settings'), 'path' => 'admin/settings/weight/settings', 'access' => $access, 'callback' => 'weight_settings_page', 'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('title' => t('db setup'), 'path' => 'admin/settings/weight/setup', 'access' => $access, 'callback' => 'weight_enable_page', 'type' => MENU_LOCAL_TASK, 'weight' => 4);
$items[] = array(
'title' => t('settings'),
'path' => 'admin/settings/weight/settings',
'access' => $access,
'callback' => 'weight_settings_page',
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items[] = array(
'title' => t('db setup'),
'path' => 'admin/settings/weight/setup',
'access' => $access,
'callback' => 'weight_enable_page',
'type' => MENU_LOCAL_TASK,
'weight' => 4
);
// 3rd level
$items[] = array('title' => t('enable'), 'path' => 'admin/settings/weight/setup/enable', 'access' => $access, 'callback' => 'weight_enable_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -2);
$items[] = array('title' => t('disable'), 'path' => 'admin/settings/weight/setup/disable', 'access' => $access, 'callback' => 'weight_disable_page', 'type' => MENU_LOCAL_TASK, 'weight' => 2);
$items[] = array(
'title' => t('enable'),
'path' => 'admin/settings/weight/setup/enable',
'access' => $access,
'callback' => 'weight_enable_page',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -2
);
$items[] = array(
'title' => t('disable'),
'path' => 'admin/settings/weight/setup/disable',
'access' => $access,
'callback' => 'weight_disable_page',
'type' => MENU_LOCAL_TASK,
'weight' => 2
);
}
return $items;
}
......@@ -150,18 +191,18 @@ function weight_form_alter($form_id, &$form){
if (in_array($node->type, variable_get('weight_node_types', array_flip(node_get_types())))) {
$range = variable_get('weight_range', 20);
$form["weight_fieldset"] = array(
'#type' => 'fieldset',
'#title' => 'Node Weight',
'#type' => 'fieldset',
'#title' => t('Node Weight'),
'#collapsible' => true,
'#collapsed' => ($node->node_weight == 0),
'#weight' => 2,
'#collapsed' => ($node->node_weight == 0),
'#weight' => 2,
);
$form["weight_fieldset"]["node_weight"] = array(
'#type' => 'weight',
'#title' => t("Node Weight"),
'#type' => 'weight',
'#title' => t("Node Weight"),
'#default_value' => $node->node_weight,
'#delta' => $range,
'#description' => t(USER_HELP),
'#delta' => $range,
'#description' => t(USER_HELP),
);
}
//return $form;
......@@ -179,7 +220,7 @@ function weight_enable_page(){
<p>%count nodes need to be updated.</p>', array('%count' => $count));
if (weight_formapi()){
$form[] = array(
'#type' => 'submit',
'#type' => 'submit',
'#value' => t('Setup Database'),
);
$output .= drupal_get_form('weight_setup', $form);
......@@ -200,7 +241,7 @@ function weight_disable_page(){
<p><strong>NOTE: Clicking this button will erase any node weights that have been set.</strong></p>');
if (weight_formapi()){
$form[] = array(
'#type' => 'submit',
'#type' => 'submit',
'#value' => t('Remove weights'),
);
$output .= drupal_get_form('weight_setup_remove', $form);
......@@ -358,27 +399,26 @@ function weight_settings_page() {
if (weight_formapi()){
$form['weight_range'] = array(
'#type' => 'select',
'#title' => t('Node Weight Range'),
'#type' => 'select',
'#title' => t('Node Weight Range'),
'#default_value' => variable_get('weight_range', 20),
'#options' => array(5=>5, 10=>10, 20=>20, 30=>30, 40=>40),
'#description' => t('This will be the +/- range for node weight.'),
'#options' => array(5=>5, 10=>10, 20=>20, 30=>30, 40=>40),
'#description' => t('This will be the +/- range for node weight.'),
);
$form['weight_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Display On'),
'#type' => 'checkboxes',
'#title' => t('Display On'),
'#default_value' => variable_get('weight_node_types', $types),
'#options' => $types,
'#description' => t("Add node weighting to these content types."),
'#options' => $types,
'#description' => t("Add node weighting to these content types."),
);
$form[] = array(
'#type' => 'submit',
'#type' => 'submit',
'#value' => t('Update'),
);
$output .= drupal_get_form('your_form_id', $form);
}
else {
$form = form_select(t('Node Weight Range'), 'weight_range', variable_get('weight_range', 20), array(5=>5, 10=>10, 20=>20, 30=>30, 40=>40), t('This will be the +/- range for node weight.'));
$form .= form_checkboxes(t('Display On'), 'weight_node_types', variable_get('weight_node_types', $types), $types, t("Add node weighting to these content types."));
$form .= form_submit(t('Update'));
......@@ -412,20 +452,4 @@ function weight_return($output){
}
}
// these are misleading. sticky is both the dual-purpose value stored in
// the database, AND a boolean indicating stickiness
function _weight2sticky($weight) {
$sticky = ($weight > 0) ? 1 : 0;
return($sticky);
}
function _sticky2weight($sticky) {
if ($sticky > 0) {
$weight = ($sticky - 100)*-1;
} else {
$weight = ($sticky + 100)*-1;
}
return($weight);
}
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment