~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/modules/user/views_handler_field_user.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

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