function weight_view_weight_form in Weight 6
Same name and namespace in other branches
- 7 weight.views.inc \weight_view_weight_form()
Display a view as a weight changing table.
1 string reference to 'weight_view_weight_form'
- weight_forms in ./
weight.module - Implementation of hook_forms().
File
- ./
weight.module, line 282 - This module uses the sticky column of the node table to add weighting to nodes.
Code
function weight_view_weight_form($form_state, $view, $renders) {
$options = $view->style_plugin->options;
$results = $view->result;
$fields = $view->field;
$id = 'weight_view_weight_form_' . $view->name . '_' . $view->current_display;
drupal_add_tabledrag($id, 'order', 'sibling', 'weight_dragger');
parse_str(tablesort_get_querystring(), $query);
if (isset($view->exposed_raw_input)) {
$query += $view->exposed_raw_input;
}
$query = empty($query) ? '' : '&' . http_build_query($query, '', '&');
$header = array();
$rows = array();
foreach ($fields as $key => $field) {
if (empty($field->options['exclude'])) {
$header[$key] = check_plain($field->options['label']);
}
}
$form['#tree'] = TRUE;
$form['header'] = array(
'#type' => 'value',
'#value' => $header,
);
foreach ($renders as $num => $result) {
foreach ($result as $field => $value) {
if ($field == 'weight') {
if (user_access('assign node weight')) {
$form['rows'][$num][$field] = array(
'#type' => 'weight',
'#delta' => variable_get('weight_range', 20),
'#default_value' => $value,
);
}
else {
$form['rows'][$num][$field] = array(
'#value' => $value,
);
}
}
else {
$form['rows'][$num][$field] = array(
'#type' => 'markup',
'#value' => $value,
);
}
}
$form['rows'][$num]['nid_hidden'] = array(
'#type' => 'value',
'#value' => $view->result[$num]->nid,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$class = 'views-table-weight';
if (!empty($options['sticky'])) {
drupal_add_js('misc/tableheader.js');
$class .= " sticky-enabled";
}
$form['class'] = array(
'#type' => 'value',
'#value' => $class,
);
$form['id'] = array(
'#type' => 'value',
'#value' => $id,
);
$form['fields'] = array(
'#type' => 'value',
'#value' => $fields,
);
$form['#theme'] = 'weight_view_weight';
if (user_access('assign node weight')) {
$form['#submit'][] = 'weight_view_weight_form_submit';
}
return $form;
}