flag_lists_handler_field_template.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. // $I$
  3. /**
  4. * @file
  5. * Contains the basic 'list template' field handler.
  6. */
  7. /**
  8. * Field handler to provide simple renderer that allows linking to a list's template flag.
  9. */
  10. class flag_lists_handler_field_template extends views_handler_field {
  11. /**
  12. * Constructor to provide additional field to add.
  13. */
  14. function construct() {
  15. parent::construct();
  16. $this->additional_fields['name'] = array('table' => 'flags', 'field' => 'name');
  17. }
  18. function option_definition() {
  19. $options = parent::option_definition();
  20. $options['link_to_template'] = array('default' => FALSE);
  21. return $options;
  22. }
  23. /**
  24. * Provide link to list option
  25. */
  26. function options_form(&$form, &$form_state) {
  27. parent::options_form($form, $form_state);
  28. $form['link_to_template'] = array(
  29. '#title' => t('Link this field to its list template'),
  30. '#description' => t('This will override any other link you have set.'),
  31. '#type' => 'checkbox',
  32. '#default_value' => !empty($this->options['link_to_template']),
  33. );
  34. }
  35. /**
  36. * Render whatever the data is as a link to the list.
  37. *
  38. * Data should be made XSS safe prior to calling this function.
  39. */
  40. function render_link($data, $values) {
  41. if (!empty($this->options['link_to_template']) && $data !== NULL && $data !== '') {
  42. $this->options['alter']['make_link'] = TRUE;
  43. $this->options['alter']['path'] = "admin/build/flags/edit/" . $values->{$this->aliases['name']};
  44. }
  45. return $data;
  46. }
  47. function render($values) {
  48. return $this->render_link(check_plain($values->{$this->field_alias}), $values);
  49. }
  50. }