1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_term_link_edit.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to present a term edit link.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_term_link_edit extends views_handler_field {
|
14
|
function construct() {
|
15
|
parent::construct();
|
16
|
$this->additional_fields['tid'] = 'tid';
|
17
|
$this->additional_fields['vid'] = 'vid';
|
18
|
$this->additional_fields['vocabulary_machine_name'] = array(
|
19
|
'table' => 'taxonomy_vocabulary',
|
20
|
'field' => 'machine_name',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
function option_definition() {
|
25
|
$options = parent::option_definition();
|
26
|
|
27
|
$options['text'] = array('default' => '', 'translatable' => TRUE);
|
28
|
|
29
|
return $options;
|
30
|
}
|
31
|
|
32
|
function options_form(&$form, &$form_state) {
|
33
|
$form['text'] = array(
|
34
|
'#type' => 'textfield',
|
35
|
'#title' => t('Text to display'),
|
36
|
'#default_value' => $this->options['text'],
|
37
|
);
|
38
|
parent::options_form($form, $form_state);
|
39
|
}
|
40
|
|
41
|
function query() {
|
42
|
$this->ensure_my_table();
|
43
|
$this->add_additional_fields();
|
44
|
}
|
45
|
|
46
|
function render($values) {
|
47
|
// Check there is an actual value, as on a relationship there may not be.
|
48
|
if ($tid = $this->get_value($values, 'tid')) {
|
49
|
// Mock a term object for taxonomy_term_edit_access(). Use machine name and
|
50
|
// vid to ensure compatibility with vid based and machine name based
|
51
|
// access checks. See http://drupal.org/node/995156
|
52
|
$term = new stdClass();
|
53
|
$term->vid = $values->{$this->aliases['vid']};
|
54
|
$term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
|
55
|
if (taxonomy_term_edit_access($term)) {
|
56
|
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
|
57
|
$tid = $this->get_value($values, 'tid');
|
58
|
return l($text, 'taxonomy/term/'. $tid . '/edit', array('query' => drupal_get_destination()));
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
}
|