QuickBlockContent.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Class for tab content of type "block" - this is for rendering a block as tab
  4. * content.
  5. */
  6. class QuickBlockContent extends QuickContent {
  7. public static function getType() {
  8. return 'block';
  9. }
  10. public function optionsForm($delta, $qt) {
  11. $tab = $this->settings;
  12. $form = array();
  13. $form['block']['bid'] = array(
  14. '#type' => 'select',
  15. '#options' => quicktabs_get_blocks(),
  16. '#default_value' => isset($tab['bid']) ? $tab['bid'] : '',
  17. '#title' => t('Select a block'),
  18. );
  19. $form['block']['hide_title'] = array(
  20. '#type' => 'checkbox',
  21. '#title' => t('Hide the title of this block'),
  22. '#default_value' => isset($tab['hide_title']) ? $tab['hide_title'] : 1,
  23. );
  24. return $form;
  25. }
  26. public function render($hide_empty = FALSE, $args = array()) {
  27. if ($this->rendered_content) {
  28. return $this->rendered_content;
  29. }
  30. $output = array();
  31. $item = $this->settings;
  32. if (!empty($args)) {
  33. // The args have been passed in from an ajax request.
  34. $qt_name = array_shift($args);
  35. list($item['bid'], $item['hide_title']) = $args;
  36. // Ensure the block is assigned to the requested quicktabs block. This test prevents
  37. // AJAX access to blocks that have not been added to an AJAX-enabled quicktabs block.
  38. $break = TRUE;
  39. $quicktabs = quicktabs_load($qt_name);
  40. // Ensure AJAX is enabled for the quicktabs block.
  41. if (!empty($quicktabs) && $quicktabs->ajax == 1) {
  42. // Ensure the requested tab has been added to the quicktabs block.
  43. foreach ($quicktabs->tabs as $quicktab) {
  44. if (isset($quicktab['bid']) && ($quicktab['bid'] == $item['bid'])) {
  45. $break = FALSE;
  46. break;
  47. }
  48. }
  49. }
  50. if ($break == TRUE) {
  51. if (!$hide_empty) {
  52. $output['#markup'] = theme('quicktabs_tab_access_denied', $item);
  53. }
  54. return $output;
  55. }
  56. }
  57. if (isset($item['bid'])) {
  58. if (module_exists('block')) {
  59. $pos = strpos($item['bid'], '_delta_');
  60. $module = drupal_substr($item['bid'], 0, $pos);
  61. $delta = drupal_substr($item['bid'], $pos + 7);
  62. $block = block_load($module, $delta);
  63. $block->region = 'quicktabs_tabpage';
  64. if ($block_arr = _block_render_blocks(array($block))) {
  65. if ($item['hide_title']) {
  66. $block_arr["{$block->module}_{$block->delta}"]->subject = FALSE;
  67. }
  68. if (!empty($block_arr["{$block->module}_{$block->delta}"]->content)) {
  69. $build = _block_get_renderable_array($block_arr);
  70. $output = $build;
  71. }
  72. }
  73. }
  74. elseif (!$hide_empty) {
  75. $output['#markup'] = t('Block module is not enabled, cannot display content.');
  76. }
  77. }
  78. $this->rendered_content = $output;
  79. return $output;
  80. }
  81. public function getAjaxKeys() {
  82. return array('bid', 'hide_title');
  83. }
  84. }