page_title.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to handle the 'page' content type which allows the standard page
  5. * template variables to be embedded into a panel.
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'single' => TRUE,
  13. 'title' => t('Page title'),
  14. 'icon' => 'icon_page.png',
  15. 'description' => t('Add the page title as content.'),
  16. 'category' => t('Page elements'),
  17. 'defaults' => array(
  18. 'markup' => 'h1',
  19. 'class' => '',
  20. 'id' => '',
  21. ),
  22. );
  23. /**
  24. * Output function for the 'page_title' content type.
  25. *
  26. * Outputs the page title of the current page.
  27. */
  28. function ctools_page_title_content_type_render($subtype, $conf, $panel_args) {
  29. // $conf['override_title'] can have one of these three values.
  30. // 0 i.e. hide the title, 1 i.e. no title, and 2 i.e. pane title if it's a
  31. // panels page.
  32. if (!drupal_get_title() && isset($conf['override_title']) && $conf['override_title'] === 1) {
  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. if (empty($conf['class'])) {
  40. $conf['class'] = '';
  41. }
  42. if (empty($conf['id'])) {
  43. $conf['id'] = '';
  44. }
  45. $token = ctools_set_callback_token('title', array('ctools_page_title_content_type_token', $conf['markup'], $conf['id'], $conf['class']));
  46. $block = new stdClass();
  47. if ($token) {
  48. $block->content = $token;
  49. }
  50. return $block;
  51. }
  52. function ctools_page_title_content_type_edit_form($form, &$form_state) {
  53. $conf = $form_state['conf'];
  54. $form['markup'] = array(
  55. '#title' => t('Title tag'),
  56. '#type' => 'select',
  57. '#options' => array(
  58. 'none' => t('- No tag -'),
  59. 'h1' => t('h1'),
  60. 'h2' => t('h2'),
  61. 'h3' => t('h3'),
  62. 'h4' => t('h4'),
  63. 'h5' => t('h5'),
  64. 'h6' => t('h6'),
  65. 'div' => t('div'),
  66. ),
  67. '#default_value' => empty($conf['markup']) ? 'h1' : $conf['markup'],
  68. );
  69. $form['id'] = array(
  70. '#title' => t('CSS id to use'),
  71. '#type' => 'textfield',
  72. '#default_value' => empty($conf['id']) ? '' : $conf['id'],
  73. );
  74. $form['class'] = array(
  75. '#title' => t('CSS class to use'),
  76. '#type' => 'textfield',
  77. '#default_value' => empty($conf['class']) ? '' : $conf['class'],
  78. );
  79. return $form;
  80. }
  81. /**
  82. * The submit form stores the data in $conf.
  83. */
  84. function ctools_page_title_content_type_edit_form_submit($form, &$form_state) {
  85. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  86. if (isset($form_state['values'][$key])) {
  87. $form_state['conf'][$key] = $form_state['values'][$key];
  88. }
  89. }
  90. }
  91. /**
  92. * Variable token callback to properly render the page title, with markup.
  93. */
  94. function ctools_page_title_content_type_token(&$variables, $tag, $id, $class) {
  95. if ($tag == 'none') {
  96. return drupal_get_title();
  97. }
  98. $output = '<' . $tag;
  99. if ($id) {
  100. $output .= ' id="' . $id . '"';
  101. }
  102. if ($class) {
  103. $output .= ' class="' . $class . '"';
  104. }
  105. $output .= '>' . drupal_get_title() . '</' . $tag . '>' . "\n";
  106. return $output;
  107. }