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

File

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