Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / page / page_title.inc @ 2c8c2b87

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
  // TODO: This should have a setting or something for the markup.
33
  if (empty($conf['markup'])) {
34
    $conf['markup'] = 'h1';
35
  }
36

    
37
  if (empty($conf['class'])) {
38
    $conf['class'] = '';
39
  }
40

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

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

    
47
  $block = new stdClass();
48
  if ($token) {
49
    $block->content = $token;
50
  }
51

    
52
  return $block;
53
}
54

    
55
function ctools_page_title_content_type_edit_form($form, &$form_state) {
56
  $conf = $form_state['conf'];
57

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

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

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

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

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

    
107
  $output = '<' . $tag;
108
  if ($id) {
109
    $output .= ' id="' . $id . '"';
110
  }
111

    
112
  if ($class) {
113
    $output .= ' class="' . $class . '"';
114
  }
115

    
116
  $output .= '>' . drupal_get_title() . '</' . $tag . '>' . "\n";
117
  return $output;
118
}