views_handler_field_user_link.inc

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

Definition of views_handler_field_user_link.

File

modules/user/views_handler_field_user_link.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_user_link.
  5. */
  6. /**
  7. * Field handler to present a link to the user.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_user_link extends views_handler_field {
  12. function construct() {
  13. parent::construct();
  14. $this->additional_fields['uid'] = 'uid';
  15. }
  16. function option_definition() {
  17. $options = parent::option_definition();
  18. $options['text'] = array('default' => '', 'translatable' => TRUE);
  19. return $options;
  20. }
  21. function options_form(&$form, &$form_state) {
  22. $form['text'] = array(
  23. '#type' => 'textfield',
  24. '#title' => t('Text to display'),
  25. '#default_value' => $this->options['text'],
  26. );
  27. parent::options_form($form, $form_state);
  28. }
  29. // An example of field level access control.
  30. function access() {
  31. return user_access('access user profiles');
  32. }
  33. function query() {
  34. $this->ensure_my_table();
  35. $this->add_additional_fields();
  36. }
  37. function render($values) {
  38. $value = $this->get_value($values, 'uid');
  39. return $this->render_link($this->sanitize_value($value), $values);
  40. }
  41. function render_link($data, $values) {
  42. $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
  43. $this->options['alter']['make_link'] = TRUE;
  44. $this->options['alter']['path'] = "user/" . $data;
  45. return $text;
  46. }
  47. }