views_handler_field_comment_username.inc

  1. 3.x modules/comment/views_handler_field_comment_username.inc
  2. 2.x modules/comment/views_handler_field_comment_username.inc

File

modules/comment/views_handler_field_comment_username.inc
View source
  1. <?php
  2. /**
  3. * Field handler to allow linking to a user account or homepage
  4. */
  5. class views_handler_field_comment_username extends views_handler_field {
  6. /**
  7. * Override init function to add uid and homepage fields.
  8. */
  9. function init(&$view, &$data) {
  10. parent::init($view, $data);
  11. $this->additional_fields['uid'] = 'uid';
  12. $this->additional_fields['homepage'] = 'homepage';
  13. }
  14. function option_definition() {
  15. $options = parent::option_definition();
  16. $options['link_to_user'] = array('default' => TRUE);
  17. return $options;
  18. }
  19. function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form['link_to_user'] = array(
  22. '#title' => t("Link this field to its user or an author's homepage"),
  23. '#type' => 'checkbox',
  24. '#default_value' => $this->options['link_to_user'],
  25. );
  26. }
  27. function render_link($data, $values) {
  28. if (!empty($this->options['link_to_user'])) {
  29. $account->uid = $values->{$this->aliases['uid']};
  30. $account->name = $values->{$this->field_alias};
  31. $account->homepage = $values->{$this->aliases['homepage']};
  32. return theme('username', $account);
  33. }
  34. else {
  35. return $data;
  36. }
  37. }
  38. function render($values) {
  39. return $this->render_link(check_plain($values->{$this->field_alias}), $values);
  40. }
  41. }