Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / user_context / user_profile.inc @ 136a805a

1
<?php
2

    
3
/**
4
 * Plugins are described by creating a $plugin array which will be used
5
 * by the system that includes this file.
6
 */
7
$plugin = array(
8
  'single' => TRUE,
9
  'title' => t('User profile'),
10
  'icon' => 'icon_user.png',
11
  'description' => t('The profile of a user.'),
12
  'required context' => new ctools_context_required(t('User'), 'user'),
13
  'category' => t('User'),
14
  'defaults' => array(
15
    'view_mode' => 'full',
16
  ),
17
);
18

    
19
/**
20
 * Render the user profile content type.
21
 */
22
function ctools_user_profile_content_type_render($subtype, $conf, $panel_args, $context) {
23
  $account = isset($context->data) ? clone $context->data : NULL;
24
  if (!$account) {
25
    return NULL;
26
  }
27

    
28
  // Retrieve all profile fields and attach to $account->content.
29
  if (!isset($account->content)) {
30
    user_build_content($account, isset($conf['view_mode']) ? $conf['view_mode'] : 'full');
31
  }
32

    
33
  $build = $account->content;
34
  // We don't need duplicate rendering info in account->content.
35
  unset($account->content);
36

    
37
  $build += array(
38
    '#theme' => 'user_profile',
39
    '#account' => $account,
40
    // @todo support view mode
41
    '#view_mode' => isset($conf['view_mode']) ? $conf['view_mode'] : 'full',
42
    // @todo do we need to support this?
43
    '#language' => NULL,
44
  );
45

    
46
  // Allow modules to modify the structured user.
47
  $type = 'user';
48
  drupal_alter(array('user_view', 'entity_view'), $build, $type);
49

    
50
  $block = new stdClass();
51
  $block->module = 'user-profile';
52
  $block->title = check_plain(format_username($account));
53
  $block->content = $build;
54

    
55
  return $block;
56
}
57

    
58
/**
59
 * Display the administrative title for a panel pane in the drag & drop UI.
60
 */
61
function ctools_user_profile_content_type_admin_title($subtype, $conf, $context) {
62
  return t('"@s" user profile', array('@s' => $context->identifier));
63
}
64

    
65
function ctools_user_profile_content_type_edit_form($form, &$form_state) {
66
  $conf = $form_state['conf'];
67
  $entity = entity_get_info('user');
68
  $view_mode_options = array();
69
  foreach ($entity['view modes'] as $mode => $option) {
70
    $view_mode_options[$mode] = $option['label'];
71
  }
72

    
73
  $form['view_mode'] = array(
74
    '#title' => t('View mode'),
75
    '#type' => 'select',
76
    '#description' => t('Select a build mode for this user.'),
77
    '#options' => $view_mode_options,
78
    '#default_value' => isset($conf['view_mode']) ? $conf['view_mode'] : 'full',
79
  );
80

    
81
  return $form;
82
}
83

    
84
function ctools_user_profile_content_type_edit_form_submit($form, &$form_state) {
85
  $form_state['conf']['view_mode'] = $form_state['values']['view_mode'];
86
}
87