| Commit | Line | Data |
|---|---|---|
| fe44beb7 | 1 | <?php |
| fe44beb7 EM |
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 | ||
| 15 | function option_definition() { | |
| 16 | $options = parent::option_definition(); | |
| 17 | $options['link_to_user'] = array('default' => TRUE); | |
| 18 | return $options; | |
| 19 | } | |
| 20 | ||
| 21 | function options_form(&$form, &$form_state) { | |
| 22 | parent::options_form($form, $form_state); | |
| 23 | $form['link_to_user'] = array( | |
| 24 | '#title' => t("Link this field to its user or an author's homepage"), | |
| 25 | '#type' => 'checkbox', | |
| 26 | '#default_value' => $this->options['link_to_user'], | |
| 27 | ); | |
| 28 | } | |
| 29 | ||
| 30 | function render_link($data, $values) { | |
| fe44beb7 | 31 | if (!empty($this->options['link_to_user'])) { |
| d8c64e8b EM |
32 | $account->uid = $values->{$this->aliases['uid']}; |
| 33 | $account->name = $values->{$this->field_alias}; | |
| 34 | $account->homepage = $values->{$this->aliases['homepage']}; | |
| 35 | ||
| fe44beb7 EM |
36 | return theme('username', $account); |
| 37 | } | |
| 38 | else { | |
| 39 | return $data; | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | function render($values) { | |
| 44 | return $this->render_link(check_plain($values->{$this->field_alias}), $values); | |
| 45 | } | |
| 46 | ||
| 47 | } |