Projet

Général

Profil

Paste
Télécharger (2,49 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / user / views_plugin_row_user_view.inc @ 4003efde

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_row_user_view.
6
 */
7

    
8
/**
9
 * A row plugin which renders a user via user_view.
10
 *
11
 * @ingroup views_row_plugins
12
 */
13
class views_plugin_row_user_view extends views_plugin_row {
14

    
15
  /**
16
   *
17
   */
18
  public $base_table = 'users';
19

    
20
  /**
21
   *
22
   */
23
  public $base_field = 'uid';
24

    
25
  // Store the users to be used for pre_render.
26
  public $users = array();
27

    
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function option_definition() {
32
    $options = parent::option_definition();
33
    $options['view_mode'] = array('default' => 'full');
34

    
35
    return $options;
36
  }
37

    
38
  /**
39
   * {@inheritdoc}
40
   */
41
  public function options_form(&$form, &$form_state) {
42
    parent::options_form($form, $form_state);
43

    
44
    $options = $this->options_form_summary_options();
45
    $form['view_mode'] = array(
46
      '#type' => 'select',
47
      '#options' => $options,
48
      '#title' => t('View mode'),
49
      '#default_value' => $this->options['view_mode'],
50
    );
51
    $form['help']['#markup'] = t("Display the user with standard user view. It might be necessary to add a user-profile.tpl.php in your theme's template folder, because the default <a href=\"@user-profile-api-link\">user-profile</a> template doesn't show the username by default.", array('@user-profile-api-link' => url('http://api.drupal.org/api/drupal/modules--user--user-profile.tpl.php/7')));
52
  }
53

    
54
  /**
55
   * Return the main options, which are shown in the summary title.
56
   */
57
  public function options_form_summary_options() {
58
    $entity_info = entity_get_info('user');
59
    $options = array();
60
    if (!empty($entity_info['view modes'])) {
61
      foreach ($entity_info['view modes'] as $mode => $settings) {
62
        $options[$mode] = $settings['label'];
63
      }
64
    }
65
    if (empty($options)) {
66
      $options = array(
67
        'full' => t('User account'),
68
      );
69
    }
70

    
71
    return $options;
72
  }
73

    
74
  /**
75
   * {@inheritdoc}
76
   */
77
  public function summary_title() {
78
    $options = $this->options_form_summary_options();
79
    return check_plain($options[$this->options['view_mode']]);
80
  }
81

    
82
  /**
83
   * {@inheritdoc}
84
   */
85
  public function pre_render($values) {
86
    $uids = array();
87
    foreach ($values as $row) {
88
      $uids[] = $row->{$this->field_alias};
89
    }
90
    $this->users = user_load_multiple($uids);
91
  }
92

    
93
  /**
94
   * {@inheritdoc}
95
   */
96
  public function render($row) {
97
    $account = $this->users[$row->{$this->field_alias}];
98
    $account->view = $this->view;
99
    $build = user_view($account, $this->options['view_mode']);
100

    
101
    return drupal_render($build);
102
  }
103

    
104
}