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

File

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