page_title.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. if (!drupal_get_title()) {
  30. return;
  31. }
  32. // TODO: This should have a setting or something for the markup.
  33. if (empty($conf['markup'])) {
  34. $conf['markup'] = 'h1';
  35. }
  36. if (empty($conf['class'])) {
  37. $conf['class'] = '';
  38. }
  39. if (empty($conf['id'])) {
  40. $conf['id'] = '';
  41. }
  42. $token = ctools_set_callback_token('title', array('ctools_page_title_content_type_token', $conf['markup'], $conf['id'], $conf['class']));
  43. $block = new stdClass();
  44. if ($token) {
  45. $block->content = $token;
  46. }
  47. return $block;
  48. }
  49. function ctools_page_title_content_type_edit_form($form, &$form_state) {
  50. $conf = $form_state['conf'];
  51. $form['markup'] = array(
  52. '#title' => t('Title tag'),
  53. '#type' => 'select',
  54. '#options' => array(
  55. 'none' => t('- No tag -'),
  56. 'h1' => t('h1'),
  57. 'h2' => t('h2'),
  58. 'h3' => t('h3'),
  59. 'h4' => t('h4'),
  60. 'h5' => t('h5'),
  61. 'h6' => t('h6'),
  62. 'div' => t('div'),
  63. ),
  64. '#default_value' => empty($conf['markup']) ? 'h1' : $conf['markup'],
  65. );
  66. $form['id'] = array(
  67. '#title' => t('CSS id to use'),
  68. '#type' => 'textfield',
  69. '#default_value' => empty($conf['id']) ? '' : $conf['id'],
  70. );
  71. $form['class'] = array(
  72. '#title' => t('CSS class to use'),
  73. '#type' => 'textfield',
  74. '#default_value' => empty($conf['class']) ? '' : $conf['class'],
  75. );
  76. return $form;
  77. }
  78. /**
  79. * The submit form stores the data in $conf.
  80. */
  81. function ctools_page_title_content_type_edit_form_submit($form, &$form_state) {
  82. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  83. if (isset($form_state['values'][$key])) {
  84. $form_state['conf'][$key] = $form_state['values'][$key];
  85. }
  86. }
  87. }
  88. /**
  89. * Variable token callback to properly render the page title, with markup.
  90. */
  91. function ctools_page_title_content_type_token(&$variables, $tag, $id, $class) {
  92. if ($tag == 'none') {
  93. return drupal_get_title();
  94. }
  95. $output = '<' . $tag;
  96. if ($id) {
  97. $output .= ' id="' . $id . '"';
  98. }
  99. if ($class) {
  100. $output .= ' class="' . $class . '"';
  101. }
  102. $output .= '>' . drupal_get_title() . '</' . $tag . '>' . "\n";
  103. return $output;
  104. }