views_plugin_row_user_view.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Contains the user view row plugin.
  5. */
  6. /**
  7. * A row plugin which renders a user via user_view.
  8. *
  9. * @ingroup views_row_plugins
  10. */
  11. class views_plugin_row_user_view extends views_plugin_row {
  12. var $base_table = 'users';
  13. var $base_field = 'uid';
  14. // Store the users to be used for pre_render.
  15. var $users = array();
  16. function option_definition() {
  17. $options = parent::option_definition();
  18. $options['view_mode'] = array('default' => 'full');
  19. return $options;
  20. }
  21. function options_form(&$form, &$form_state) {
  22. parent::options_form($form, $form_state);
  23. $options = $this->options_form_summary_options();
  24. $form['view_mode'] = array(
  25. '#type' => 'select',
  26. '#options' => $options,
  27. '#title' => t('View mode'),
  28. '#default_value' => $this->options['view_mode'],
  29. );
  30. $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')));
  31. }
  32. /**
  33. * Return the main options, which are shown in the summary title.
  34. */
  35. function options_form_summary_options() {
  36. $entity_info = entity_get_info('user');
  37. $options = array();
  38. if (!empty($entity_info['view modes'])) {
  39. foreach ($entity_info['view modes'] as $mode => $settings) {
  40. $options[$mode] = $settings['label'];
  41. }
  42. }
  43. if (empty($options)) {
  44. $options = array(
  45. 'full' => t('User account')
  46. );
  47. }
  48. return $options;
  49. }
  50. function summary_title() {
  51. $options = $this->options_form_summary_options();
  52. return check_plain($options[$this->options['view_mode']]);
  53. }
  54. function pre_render($values) {
  55. $uids = array();
  56. foreach ($values as $row) {
  57. $uids[] = $row->{$this->field_alias};
  58. }
  59. $this->users = user_load_multiple($uids);
  60. }
  61. function render($row) {
  62. $account = $this->users[$row->{$this->field_alias}];
  63. $account->view = $this->view;
  64. $build = user_view($account, $this->options['view_mode']);
  65. return drupal_render($build);
  66. }
  67. }