Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / page / page_title.inc @ 7e72b748

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
  // $conf['override_title'] can have one of these three values.
33
  // 0 i.e. hide the title, 1 i.e. no title, and 2 i.e. pane title if it's a
34
  // panels page.
35
  if (!drupal_get_title() && isset($conf['override_title']) && $conf['override_title'] === 1) {
36
    return;
37
  }
38
  // TODO: This should have a setting or something for the markup.
39
  if (empty($conf['markup'])) {
40
    $conf['markup'] = 'h1';
41
  }
42

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

    
47
  if (empty($conf['id'])) {
48
    $conf['id'] = '';
49
  }
50

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

    
53
  $block = new stdClass();
54
  if ($token) {
55
    $block->content = $token;
56
  }
57

    
58
  return $block;
59
}
60

    
61
function ctools_page_title_content_type_edit_form($form, &$form_state) {
62
  $conf = $form_state['conf'];
63

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

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

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

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

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

    
113
  $output = '<' . $tag;
114
  if ($id) {
115
    $output .= ' id="' . $id . '"';
116
  }
117

    
118
  if ($class) {
119
    $output .= ' class="' . $class . '"';
120
  }
121

    
122
  $output .= '>' . drupal_get_title() . '</' . $tag . '>' . "\n";
123
  return $output;
124
}