summaryrefslogtreecommitdiff
path: root/sites/all/modules/views/modules/user/views_plugin_row_user_view.inc
blob: b48f4596e5ae7abbbb37e3b3f18aa856cda0fa10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

/**
 * @file
 * Contains the user view row plugin.
 */

/**
 * A row plugin which renders a user via user_view.
 *
 * @ingroup views_row_plugins
 */
class views_plugin_row_user_view extends views_plugin_row {
  var $base_table = 'users';
  var $base_field = 'uid';

  // Store the users to be used for pre_render.
  var $users = array();

  function option_definition() {
    $options = parent::option_definition();
    $options['view_mode'] = array('default' => 'full');

    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    $options = $this->options_form_summary_options();
    $form['view_mode'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => t('View mode'),
      '#default_value' => $this->options['view_mode'],
     );
    $form['help']['#markup'] = t("Display the user with standard user view. It might be necessary to add a user-profile.tpl.php in your themes template folder, because the default <a href=\"@user-profile-api-link\">user-profile</a>e template don't show the username per default.", array('@user-profile-api-link' => url('http://api.drupal.org/api/drupal/modules--user--user-profile.tpl.php/7')));
  }


    /**
     * Return the main options, which are shown in the summary title.
     */
    function options_form_summary_options() {
      $entity_info = entity_get_info('user');
      $options = array();
      if (!empty($entity_info['view modes'])) {
        foreach ($entity_info['view modes'] as $mode => $settings) {
          $options[$mode] = $settings['label'];
        }
      }
      if (empty($options)) {
        $options = array(
          'full' => t('User account')
        );
      }

      return $options;
    }

    function summary_title() {
      $options = $this->options_form_summary_options();
      return check_plain($options[$this->options['view_mode']]);
    }

  function pre_render($values) {
    $uids = array();
    foreach ($values as $row) {
      $uids[] = $row->{$this->field_alias};
    }
    $this->users = user_load_multiple($uids);
  }

  function render($row) {
    $account = $this->users[$row->{$this->field_alias}];
    $account->view = $this->view;
    $build = user_view($account, $this->options['view_mode']);

    return drupal_render($build);
  }
}