| 1 |
|
<?php |
| 2 |
|
class fasttoggle_views_handler_field_node_link extends views_handler_field_node_link { |
| 3 |
|
var $fasttoggle_key = 'status'; |
| 4 |
|
|
| 5 |
|
function construct() { |
| 6 |
|
parent::construct(); |
| 7 |
|
|
| 8 |
|
// We need these fields for access checking later in the render() function. |
| 9 |
|
$this->additional_fields['uid'] = 'uid'; |
| 10 |
|
$this->additional_fields['status'] = 'status'; |
| 11 |
|
$this->additional_fields['type'] = 'type'; |
| 12 |
|
$this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format'); |
| 13 |
|
|
| 14 |
|
if (isset($this->definition['fasttoggle'])) { |
| 15 |
|
if (isset($this->definition['fasttoggle']['additional_fields'])) { |
| 16 |
|
$this->additional_fields += $this->definition['fasttoggle']['additional_fields']; |
| 17 |
|
} |
| 18 |
|
if (isset($this->definition['fasttoggle']['key'])) { |
| 19 |
|
$this->fasttoggle_key = $this->definition['fasttoggle']['key']; |
| 20 |
|
} |
| 21 |
|
} |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
function options_form(&$form, &$form_state) { |
| 25 |
|
parent::options_form($form, $form_state); |
| 26 |
|
unset($form['text']); |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
function render($values) { |
| 30 |
|
// ensure user has access to edit this node. |
| 31 |
|
$node = new stdClass(); |
| 32 |
|
foreach (array('nid', 'uid', 'type', 'format') as $key) { |
| 33 |
|
$node->$key = $values->{$this->aliases[$key]}; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
// node_access() ignores access control for unpublished nodes. Since |
| 37 |
|
// this is a faked node object anyway, we can set status to 1 safely. |
| 38 |
|
$node->status = 1; |
| 39 |
|
if (!node_access('update', $node)) { |
| 40 |
|
return ''; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
// Now we set the status to the actual value so that we get the |
| 44 |
|
// correct labels. |
| 45 |
|
$node->status = $values->{$this->aliases['status']}; |
| 46 |
|
$options = fasttoggle_get_options('node', $node); |
| 47 |
|
|
| 48 |
|
$key = $this->fasttoggle_key; |
| 49 |
|
|
| 50 |
|
if (!empty($options[$key])) { |
| 51 |
|
$node->$key = $values->{$this->aliases[$key]}; |
| 52 |
|
return fasttoggle($options[$key][intval($node->$key)], 'node/'. $node->nid .'/toggle/'. $key, TRUE, $key .'_'. $node->nid); |
| 53 |
|
} |
| 54 |
|
} |
| 55 |
|
} |