Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_title.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 title'),
12
  'icon' => 'icon_node.png',
13
  'description' => t('The title 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
    'markup' => 'none',
19
    'id' => '',
20
    'class' => '',
21
  ),
22
);
23

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

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

    
35
  // Load information about the node type.
36
  $type = node_type_get_type($node);
37

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

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

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

    
61
  return $block;
62
}
63

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

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

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

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

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

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

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