views_handler_argument_field_list.inc

Definition of views_handler_argument_field_list.

File

modules/field/views_handler_argument_field_list.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_argument_field_list.
  5. */
  6. /**
  7. * Argument handler for list field to show the human readable name in the
  8. * summary.
  9. *
  10. * @ingroup views_argument_handlers
  11. */
  12. class views_handler_argument_field_list extends views_handler_argument_numeric {
  13. /**
  14. * Stores the allowed values of this field.
  15. *
  16. * @var array
  17. */
  18. var $allowed_values = NULL;
  19. function init(&$view, &$options) {
  20. parent::init($view, $options);
  21. $field = field_info_field($this->definition['field_name']);
  22. $this->allowed_values = list_allowed_values($field);
  23. }
  24. function option_definition() {
  25. $options = parent::option_definition();
  26. $options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
  27. return $options;
  28. }
  29. function options_form(&$form, &$form_state) {
  30. parent::options_form($form, $form_state);
  31. $form['summary']['human'] = array(
  32. '#title' => t('Display list value as human readable'),
  33. '#type' => 'checkbox',
  34. '#default_value' => $this->options['summary']['human'],
  35. '#dependency' => array('radio:options[default_action]' => array('summary')),
  36. );
  37. }
  38. function summary_name($data) {
  39. $value = $data->{$this->name_alias};
  40. // If the list element has a human readable name show it,
  41. if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
  42. return field_filter_xss($this->allowed_values[$value]);
  43. }
  44. // else fallback to the key.
  45. else {
  46. return check_plain($value);
  47. }
  48. }
  49. }