Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_title.inc @ 7e72b748

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('Node title'),
10
  'icon' => 'icon_node.png',
11
  'description' => t('The title of the referenced node.'),
12
  'required context' => new ctools_context_required(t('Node'), 'node'),
13
  'category' => t('Node'),
14
  'defaults' => array(
15
    'link' => TRUE,
16
    'markup' => 'none',
17
    'id' => '',
18
    'class' => '',
19
  ),
20
);
21

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

    
30
  // Get a shortcut to the node.
31
  $node = $context->data;
32

    
33
  // Load information about the node type.
34
  $type = node_type_get_type($node);
35

    
36
  // Generate the title
37
  $content = !empty($conf['link']) ? l($node->title, 'node/' . $node->nid) : check_plain($node->title);
38

    
39
  // Build any surrounding markup if so configured
40
  if (isset($conf['markup']) && $conf['markup'] != 'none') {
41
    $markup = '<' . $conf['markup'];
42
    if (!empty($conf['id'])) {
43
      $markup .= ' id="' . $conf['id'] . '"';
44
    }
45
    if (!empty($conf['class'])) {
46
      $markup .= ' class="' . $conf['class'] . '"';
47
    }
48
    $markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
49
    $content = $markup;
50
  }
51

    
52
  // Build the content type block.
53
  $block = new stdClass();
54
  $block->module  = 'node_title';
55
  $block->title   = $type->title_label;
56
  $block->content = $content;
57
  $block->delta   = $node->nid;
58

    
59
  return $block;
60
}
61

    
62
/**
63
 * Returns an edit form for custom type settings.
64
 */
65
function ctools_node_title_content_type_edit_form($form, &$form_state) {
66
  $conf = $form_state['conf'];
67

    
68
  $form['markup'] = array(
69
    '#title' => t('Title tag'),
70
    '#type' => 'select',
71
    '#options' => array(
72
      'none' => t('- No tag -'),
73
      'h1' => t('h1'),
74
      'h2' => t('h2'),
75
      'h3' => t('h3'),
76
      'h4' => t('h4'),
77
      'h5' => t('h5'),
78
      'h6' => t('h6'),
79
      'div' => t('div'),
80
    ),
81
    '#default_value' => $conf['markup'],
82
  );
83

    
84
  $form['id'] = array(
85
    '#title' => t('CSS id to use'),
86
    '#type' => 'textfield',
87
    '#default_value' => $conf['id'],
88
  );
89

    
90
  $form['class'] = array(
91
    '#title' => t('CSS class to use'),
92
    '#type' => 'textfield',
93
    '#default_value' => $conf['class'],
94
  );
95

    
96
  $form['link'] = array(
97
    '#title' => t('Link to node'),
98
    '#type' => 'checkbox',
99
    '#default_value' => $conf['link'],
100
    '#description' => t('Check here to make the title link to the node.'),
101
  );
102
  return $form;
103
}
104

    
105
/**
106
 * Submit handler for the custom type settings form.
107
 */
108
function ctools_node_title_content_type_edit_form_submit($form, &$form_state) {
109
  // Copy everything from our defaults.
110
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
111
    $form_state['conf'][$key] = $form_state['values'][$key];
112
  }
113
}
114

    
115
/**
116
 * Returns the administrative title for a type.
117
 */
118
function ctools_node_title_content_type_admin_title($subtype, $conf, $context) {
119
  return t('"@s" title', array('@s' => $context->identifier));
120
}