Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugins are described by creating a $plugin array which will be used
6
 * by the system that includes this file.
7
 */
8

    
9
$plugin = array(
10
  'single' => TRUE,
11
  'title' => t('User profile'),
12
  'icon' => 'icon_user.png',
13
  'description' => t('The profile of a user.'),
14
  'required context' => new ctools_context_required(t('User'), 'user'),
15
  'category' => t('User'),
16
  'defaults' => array(
17
    'view_mode' => 'full',
18
  ),
19
);
20

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

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

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

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

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

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

    
57
  return $block;
58
}
59

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

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

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

    
83
  return $form;
84
}
85

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