QuickQtabsContent.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Class for tab content of type "qtabs" - this is for rendering a QuickSet instance
  4. * as the tab content of another QuickSet instance.
  5. */
  6. class QuickQtabsContent extends QuickContent {
  7. public static function getType() {
  8. return 'qtabs';
  9. }
  10. public function optionsForm($delta, $qt) {
  11. $tab = $this->settings;
  12. $form = array();
  13. $tab_options = array();
  14. foreach (quicktabs_load_multiple() as $machine_name => $info) {
  15. // Do not offer the option to put a tab inside itself.
  16. if (!isset($qt->machine_name) || $machine_name != $qt->machine_name) {
  17. $tab_options[$machine_name] = $info->title;
  18. }
  19. }
  20. $form['qtabs']['machine_name'] = array(
  21. '#type' => 'select',
  22. '#title' => t('Quicktabs instance'),
  23. '#description' => t('The Quicktabs instance to put inside this tab.'),
  24. '#options' => $tab_options,
  25. '#default_value' => isset($tab['machine_name']) ? $tab['machine_name'] : '',
  26. );
  27. return $form;
  28. }
  29. public function render($hide_empty = FALSE, $args = array()) {
  30. if ($this->rendered_content) {
  31. return $this->rendered_content;
  32. }
  33. $item = $this->settings;
  34. if (!empty($args)) {
  35. // The args have been passed in from an ajax request.
  36. // The first element of the args array is the qt_name, which we don't need
  37. // for this content type.
  38. array_shift($args);
  39. $item['machine_name'] = $args[0];
  40. }
  41. $output = array();
  42. if (isset($item['machine_name'])) {
  43. if ($quicktabs = quicktabs_load($item['machine_name'])) {
  44. $contents = $quicktabs->tabs;
  45. $name = $quicktabs->machine_name;
  46. unset($quicktabs->tabs, $quicktabs->machine_name);
  47. $options = (array) $quicktabs;
  48. if ($qt = QuickSet::QuickSetRendererFactory($name, $contents, $quicktabs->renderer, $options)) {
  49. $output = $qt->render();
  50. }
  51. }
  52. }
  53. $this->rendered_content = $output;
  54. return $output;
  55. }
  56. public function getAjaxKeys() {
  57. return array('machine_name');
  58. }
  59. }