user_profile.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Plugins are described by creating a $plugin array which will be used
  4. * by the system that includes this file.
  5. */
  6. $plugin = array(
  7. 'single' => TRUE,
  8. 'title' => t('User profile'),
  9. 'icon' => 'icon_user.png',
  10. 'description' => t('The profile of a user.'),
  11. 'required context' => new ctools_context_required(t('User'), 'user'),
  12. 'category' => t('User'),
  13. 'defaults' => array(
  14. 'view_mode' => 'full',
  15. ),
  16. );
  17. /**
  18. * Render the user profile content type.
  19. */
  20. function ctools_user_profile_content_type_render($subtype, $conf, $panel_args, $context) {
  21. $account = isset($context->data) ? clone $context->data : NULL;
  22. if (!$account) {
  23. return NULL;
  24. }
  25. // Retrieve all profile fields and attach to $account->content.
  26. if (!isset($account->content)) {
  27. user_build_content($account, isset($conf['view_mode']) ? $conf['view_mode'] : 'full');
  28. }
  29. $build = $account->content;
  30. // We don't need duplicate rendering info in account->content.
  31. unset($account->content);
  32. $build += array(
  33. '#theme' => 'user_profile',
  34. '#account' => $account,
  35. // @todo support view mode
  36. '#view_mode' => isset($conf['view_mode']) ? $conf['view_mode'] : 'full',
  37. // @todo do we need to support this?
  38. '#language' => NULL,
  39. );
  40. // Allow modules to modify the structured user.
  41. $type = 'user';
  42. drupal_alter(array('user_view', 'entity_view'), $build, $type);
  43. $block = new stdClass();
  44. $block->module = 'user-profile';
  45. $block->title = check_plain(format_username($account));
  46. $block->content = $build;
  47. return $block;
  48. }
  49. /**
  50. * Display the administrative title for a panel pane in the drag & drop UI.
  51. */
  52. function ctools_user_profile_content_type_admin_title($subtype, $conf, $context) {
  53. return t('"@s" user profile', array('@s' => $context->identifier));
  54. }
  55. function ctools_user_profile_content_type_edit_form($form, &$form_state) {
  56. $conf = $form_state['conf'];
  57. $entity = entity_get_info('user');
  58. $view_mode_options = array();
  59. foreach ($entity['view modes'] as $mode => $option) {
  60. $view_mode_options[$mode] = $option['label'];
  61. }
  62. $form['view_mode'] = array(
  63. '#title' => t('View mode'),
  64. '#type' => 'select',
  65. '#description' => t('Select a build mode for this user.'),
  66. '#options' => $view_mode_options,
  67. '#default_value' => isset($conf['view_mode']) ? $conf['view_mode'] : 'full',
  68. );
  69. return $form;
  70. }
  71. function ctools_user_profile_content_type_edit_form_submit($form, &$form_state) {
  72. $form_state['conf']['view_mode'] = $form_state['values']['view_mode'];
  73. }