Projet

Général

Profil

Paste
Télécharger (1,97 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_author.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('Node author'),
12
  'icon' => 'icon_node.png',
13
  'description' => t('The author of the referenced node.'),
14
  'required context' => new ctools_context_required(t('Node'), 'node'),
15
  'category' => t('Node'),
16
  'defaults' => array(
17
    'link' => TRUE,
18
  ),
19
);
20

    
21
/**
22
 * Render the custom content type.
23
 */
24
function ctools_node_author_content_type_render($subtype, $conf, $panel_args, $context) {
25
  if (empty($context) || empty($context->data)) {
26
    return;
27
  }
28

    
29
  // Get a shortcut to the node.
30
  $node = $context->data;
31
  $user = user_load($node->uid);
32

    
33
  // Build the content type block.
34
  $block          = new stdClass();
35
  $block->module  = 'node_author';
36
  $block->title   = t('Author');
37
  $block->content = !empty($conf['link']) ? theme('username', array('account' => $user, 'link_path' => 'user/' . $node->uid)) : check_plain(format_username($node));
38
  $block->delta   = $node->nid;
39

    
40
  return $block;
41
}
42

    
43
/**
44
 * Returns an edit form for custom type settings.
45
 */
46
function ctools_node_author_content_type_edit_form($form, &$form_state) {
47
  $conf = $form_state['conf'];
48

    
49
  $form['link'] = array(
50
    '#title' => t('Link to author profile'),
51
    '#type' => 'checkbox',
52
    '#default_value' => $conf['link'],
53
    '#description' => t('Check here to link to the node author profile.'),
54
  );
55
  return $form;
56
}
57

    
58
/**
59
 * Submit handler for the custom type settings form.
60
 */
61
function ctools_node_author_content_type_edit_form_submit($form, &$form_state) {
62
  // Copy everything from our defaults.
63
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
64
    $form_state['conf'][$key] = $form_state['values'][$key];
65
  }
66
}
67

    
68
/**
69
 * Returns the administrative title for a type.
70
 */
71
function ctools_node_author_content_type_admin_title($subtype, $conf, $context) {
72
  return t('"@s" author', array('@s' => $context->identifier));
73
}