views_handler_field_user.inc

  1. 3.x modules/user/views_handler_field_user.inc
  2. 2.x modules/user/views_handler_field_user.inc

Definition of views_handler_field_user.

File

modules/user/views_handler_field_user.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_user.
  5. */
  6. /**
  7. * Field handler to provide simple renderer that allows linking to a user.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_user extends views_handler_field {
  12. /**
  13. * Override init function to provide generic option to link to user.
  14. */
  15. function init(&$view, &$data) {
  16. parent::init($view, $data);
  17. if (!empty($this->options['link_to_user'])) {
  18. $this->additional_fields['uid'] = 'uid';
  19. }
  20. }
  21. function option_definition() {
  22. $options = parent::option_definition();
  23. $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
  24. return $options;
  25. }
  26. /**
  27. * Provide link to node option
  28. */
  29. function options_form(&$form, &$form_state) {
  30. $form['link_to_user'] = array(
  31. '#title' => t('Link this field to its user'),
  32. '#description' => t("Enable to override this field's links."),
  33. '#type' => 'checkbox',
  34. '#default_value' => $this->options['link_to_user'],
  35. );
  36. parent::options_form($form, $form_state);
  37. }
  38. function render_link($data, $values) {
  39. if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($uid = $this->get_value($values, 'uid')) && $data !== NULL && $data !== '') {
  40. $this->options['alter']['make_link'] = TRUE;
  41. $this->options['alter']['path'] = "user/" . $uid;
  42. }
  43. return $data;
  44. }
  45. function render($values) {
  46. $value = $this->get_value($values);
  47. return $this->render_link($this->sanitize_value($value), $values);
  48. }
  49. }