views_handler_field_term_link_edit.inc

Definition of views_handler_field_term_link_edit.

File

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