Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / page / page_title.inc @ 560c3060

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to handle the 'page' content type which allows the standard page
6
 * template variables to be embedded into a panel.
7
 */
8

    
9
/**
10
 * Plugins are described by creating a $plugin array which will be used
11
 * by the system that includes this file.
12
 */
13
$plugin = array(
14
  'single' => TRUE,
15
  'title' => t('Page title'),
16
  'icon' => 'icon_page.png',
17
  'description' => t('Add the page title as content.'),
18
  'category' => t('Page elements'),
19
  'defaults' => array(
20
    'markup' => 'h1',
21
    'class' => '',
22
    'id' => '',
23
  ),
24
);
25

    
26
/**
27
 * Output function for the 'page_title' content type.
28
 *
29
 * Outputs the page title of the current page.
30
 */
31
function ctools_page_title_content_type_render($subtype, $conf, $panel_args) {
32
  if (!drupal_get_title()) {
33
    return;
34
  }
35
  // TODO: This should have a setting or something for the markup.
36
  if (empty($conf['markup'])) {
37
    $conf['markup'] = 'h1';
38
  }
39

    
40
  if (empty($conf['class'])) {
41
    $conf['class'] = '';
42
  }
43

    
44
  if (empty($conf['id'])) {
45
    $conf['id'] = '';
46
  }
47

    
48
  $token = ctools_set_callback_token('title', array('ctools_page_title_content_type_token', $conf['markup'], $conf['id'], $conf['class']));
49

    
50
  $block = new stdClass();
51
  if ($token) {
52
    $block->content = $token;
53
  }
54

    
55
  return $block;
56
}
57

    
58
function ctools_page_title_content_type_edit_form($form, &$form_state) {
59
  $conf = $form_state['conf'];
60

    
61
  $form['markup'] = array(
62
    '#title' => t('Title tag'),
63
    '#type' => 'select',
64
    '#options' => array(
65
      'none' => t('- No tag -'),
66
      'h1' => t('h1'),
67
      'h2' => t('h2'),
68
      'h3' => t('h3'),
69
      'h4' => t('h4'),
70
      'h5' => t('h5'),
71
      'h6' => t('h6'),
72
      'div' => t('div'),
73
    ),
74
    '#default_value' => empty($conf['markup']) ? 'h1' : $conf['markup'],
75
  );
76

    
77
  $form['id'] = array(
78
    '#title' => t('CSS id to use'),
79
    '#type' => 'textfield',
80
    '#default_value' => empty($conf['id']) ? '' : $conf['id'],
81
  );
82

    
83
  $form['class'] = array(
84
    '#title' => t('CSS class to use'),
85
    '#type' => 'textfield',
86
    '#default_value' => empty($conf['class']) ? '' : $conf['class'],
87
  );
88
  return $form;
89
}
90

    
91
/**
92
 * The submit form stores the data in $conf.
93
 */
94
function ctools_page_title_content_type_edit_form_submit($form, &$form_state) {
95
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
96
    if (isset($form_state['values'][$key])) {
97
      $form_state['conf'][$key] = $form_state['values'][$key];
98
    }
99
  }
100
}
101

    
102
/**
103
 * Variable token callback to properly render the page title, with markup.
104
 */
105
function ctools_page_title_content_type_token(&$variables, $tag, $id, $class) {
106
  if ($tag == 'none') {
107
    return drupal_get_title();
108
  }
109

    
110
  $output = '<' . $tag;
111
  if ($id) {
112
    $output .= ' id="' . $id . '"';
113
  }
114

    
115
  if ($class) {
116
    $output .= ' class="' . $class . '"';
117
  }
118

    
119
  $output .= '>' . drupal_get_title() . '</' . $tag . '>' . "\n";
120
  return $output;
121
}