panels_extra_styles.module 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @file
  4. * Additional styles for the Panels module.
  5. */
  6. /**
  7. * Implements hook_ctools_plugin_directory().
  8. */
  9. function panels_extra_styles_ctools_plugin_directory($owner, $plugin_type) {
  10. if ($owner == 'panels') {
  11. return "plugins/$plugin_type";
  12. }
  13. }
  14. /**
  15. * Render region callback.
  16. *
  17. * - Wrapper: Element.
  18. * - Wrapper: Raw.
  19. */
  20. function theme_panels_extra_styles_wrapper_render_region($vars) {
  21. $content = $vars['panes'];
  22. $settings = $vars['settings'];
  23. // Theme.
  24. if (!empty($settings['theme']) && $settings['theme']) {
  25. $output = theme('panels_default_style_render_region', $vars);
  26. }
  27. else {
  28. $output = implode(PHP_EOL, $content);
  29. }
  30. // Content is wrapped AFTER sending to Panels theming. This behavior is
  31. // different than with panes.
  32. if (!empty($output)) {
  33. $content_wrapper = _panels_extra_styles_wrapper_wrap(!empty($settings['content']) ? $settings['content'] : array());
  34. $output
  35. = $content_wrapper['prefix'] .
  36. $output .
  37. $content_wrapper['suffix'];
  38. }
  39. return $output;
  40. }
  41. /**
  42. * Render pane callback.
  43. *
  44. * - Wrapper: Element.
  45. * - Wrapper: Raw.
  46. */
  47. function theme_panels_extra_styles_wrapper_render_pane(&$vars) {
  48. $content = &$vars['content'];
  49. $settings = $vars['settings'];
  50. // Content is wrapped BEFORE sending to Panels theming. This behavior is
  51. // different than with regions.
  52. if (!empty($content->title)) {
  53. $title_wrapper = _panels_extra_styles_wrapper_wrap(!empty($settings['title']) ? $settings['title'] : array());
  54. $content->title
  55. = $title_wrapper['prefix'] .
  56. $content->title .
  57. $title_wrapper['suffix'];
  58. }
  59. if (!empty($content->content)) {
  60. $content_wrapper = _panels_extra_styles_wrapper_wrap(!empty($settings['content']) ? $settings['content'] : array());
  61. $content->content
  62. = $content_wrapper['prefix'] .
  63. render($content->content) .
  64. $content_wrapper['suffix'];
  65. }
  66. // Theme.
  67. if (!empty($settings['theme']) && $settings['theme']) {
  68. $output = theme('panels_pane', $vars);
  69. }
  70. else {
  71. $title = !empty($content->title) ? $content->title : NULL;
  72. $content = !empty($content->content) ? $content->content : NULL;
  73. $output = $title . $content;
  74. }
  75. return $output;
  76. }
  77. /**
  78. * Wrap it, wrap it real good.
  79. *
  80. * @return array
  81. * Array with prefix and suffix keys.
  82. */
  83. function _panels_extra_styles_wrapper_wrap($item = array()) {
  84. $wrap['prefix'] = NULL;
  85. $wrap['suffix'] = NULL;
  86. $wrap['attributes'] = NULL;
  87. if (!empty($item['attributes'])) {
  88. foreach ($item['attributes'] as $key => $value) {
  89. if (!empty($value)) {
  90. $wrap['attributes'] .= " $key=\"$value\"";
  91. }
  92. }
  93. }
  94. if (!empty($item['element']) && $item['element'] != 'no_wrapper') {
  95. $wrap['prefix'] = '<' . $item['element'] . $wrap['attributes'] . '>';
  96. $wrap['suffix'] = '</' . $item['element'] . '>';
  97. }
  98. if (!empty($item['prefix'])) {
  99. $wrap['prefix'] = $item['prefix'];
  100. }
  101. if (!empty($item['suffix'])) {
  102. $wrap['suffix'] = $item['suffix'];
  103. }
  104. // Tidy.
  105. $wrap['prefix'] = PHP_EOL . $wrap['prefix'];
  106. $wrap['suffix'] = $wrap['suffix'] . PHP_EOL;
  107. return $wrap;
  108. }