Projet

Général

Profil

Paste
Télécharger (2,14 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / taxonomy / views_handler_field_term_link_edit.inc @ 4003efde

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

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function construct() {
19
    parent::construct();
20
    $this->additional_fields['tid'] = 'tid';
21
    $this->additional_fields['vid'] = 'vid';
22
    $this->additional_fields['vocabulary_machine_name'] = array(
23
      'table' => 'taxonomy_vocabulary',
24
      'field' => 'machine_name',
25
    );
26
  }
27

    
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function option_definition() {
32
    $options = parent::option_definition();
33

    
34
    $options['text'] = array('default' => '', 'translatable' => TRUE);
35

    
36
    return $options;
37
  }
38

    
39
  /**
40
   * {@inheritdoc}
41
   */
42
  public function options_form(&$form, &$form_state) {
43
    $form['text'] = array(
44
      '#type' => 'textfield',
45
      '#title' => t('Text to display'),
46
      '#default_value' => $this->options['text'],
47
    );
48
    parent::options_form($form, $form_state);
49
  }
50

    
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public function query() {
55
    $this->ensure_my_table();
56
    $this->add_additional_fields();
57
  }
58

    
59
  /**
60
   * {@inheritdoc}
61
   */
62
  function render($values) {
63
    $value = $this->get_value($values, 'tid');
64
    return $this->render_link($this->sanitize_value($value), $values);
65
  }
66

    
67
  /**
68
   * {@inheritdoc}
69
   */
70
  function render_link($data, $values) {
71
    // Mock a term object for taxonomy_term_edit_access(). Use machine name and
72
    // vid to ensure compatibility with vid based and machine name based
73
    // access checks. See http://drupal.org/node/995156
74
    $term = new stdClass();
75
    $term->vid = $values->{$this->aliases['vid']};
76
    $term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
77
    if ($data && taxonomy_term_edit_access($term)) {
78
      $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
79
      $this->options['alter']['make_link'] = TRUE;
80
      $this->options['alter']['path'] = "taxonomy/term/$data/edit";
81
      $this->options['alter']['query'] = drupal_get_destination();
82
      return $text;
83
    }
84
  }
85

    
86
}