Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / user_context / user_links.inc @ e4c061ad

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 links'),
10
  'icon' => 'icon_user.png',
11
  'description' => t('User links of the referenced user.'),
12
  'required context' => new ctools_context_required(t('User'), 'user'),
13
  'category' => t('User'),
14
  'defaults' => array(
15
    'override_title' => FALSE,
16
    'override_title_text' => '',
17
    'build_mode' => '',
18
  ),
19
);
20

    
21
/**
22
 * Output function for the user links.
23
 */
24
function ctools_user_links_content_type_render($subtype, $conf, $panel_args, $context) {
25
  if (!empty($context) && empty($context->data)) {
26
    return;
27
  }
28

    
29
  $account = clone $context->data;
30
  $block = new stdClass();
31
  $block->module = 'user';
32
  $block->delta  = $account->uid;
33

    
34
  if (empty($account)) {
35
    $block->delta   = 'placeholder';
36
    $block->subject = t('User name.');
37
    $block->content = t('User links go here.');
38
  }
39
  else {
40
    $block->subject = $account->name;
41
    user_build_content($account, $conf['build_mode']);
42
    if (!empty($account->content['links'])) {
43
      $block->content = $account->content['links'];
44
    }
45
    else {
46
      $block->content = '';
47
    }
48
  }
49
  return $block;
50
}
51

    
52
/**
53
 * Returns an edit form for the custom type.
54
 */
55
function ctools_user_links_content_type_edit_form($form, &$form_state) {
56
  $conf = $form_state['conf'];
57

    
58
  $entity = entity_get_info('user');
59
  $build_mode_options = array();
60
  foreach ($entity['view modes'] as $mode => $option) {
61
    $build_mode_options[$mode] = $option['label'];
62
  }
63

    
64
  $form['build_mode'] = array(
65
    '#title' => t('Build mode'),
66
    '#type' => 'select',
67
    '#description' => t('Select a build mode for this user.'),
68
    '#options' => $build_mode_options,
69
    '#default_value' => $conf['build_mode'],
70
  );
71

    
72
  return $form;
73
}
74

    
75
function ctools_user_links_content_type_edit_form_submit($form, &$form_state) {
76
  // Copy everything from our defaults.
77
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
78
    $form_state['conf'][$key] = $form_state['values'][$key];
79
  }
80
}
81

    
82
function ctools_user_links_content_type_admin_title($subtype, $conf, $context) {
83
  return t('"@s" links', array('@s' => $context->identifier));
84
}