QuickNodeContent.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Class for tab content of type "node" - this is for rendering a node as tab
  4. * content.
  5. */
  6. class QuickNodeContent extends QuickContent {
  7. public static function getType() {
  8. return 'node';
  9. }
  10. public function optionsForm($delta, $qt) {
  11. $tab = $this->settings;
  12. $form = array();
  13. $form['node']['nid'] = array(
  14. '#type' => 'textfield',
  15. '#title' => t('Node'),
  16. '#description' => t('The node ID of the node.'),
  17. '#maxlength' => 10,
  18. '#size' => 20,
  19. '#default_value' => isset($tab['nid']) ? $tab['nid'] : '',
  20. );
  21. $form['node']['teaser'] = array(
  22. '#type' => 'checkbox',
  23. '#title' => t('Teaser view'),
  24. '#default_value' => isset($tab['teaser']) ? $tab['teaser'] : 0,
  25. );
  26. $form['node']['hide_title'] = array(
  27. '#type' => 'checkbox',
  28. '#title' => t('Hide the title of this node'),
  29. '#default_value' => isset($tab['hide_title']) ? $tab['hide_title'] : 1,
  30. );
  31. return $form;
  32. }
  33. public function render($hide_empty = FALSE, $args = array()) {
  34. if ($this->rendered_content) {
  35. return $this->rendered_content;
  36. }
  37. $item = $this->settings;
  38. if (!empty($args)) {
  39. // The args have been passed in from an ajax request.
  40. // The first element of the args array is the qt_name, which we don't need
  41. // for this content type.
  42. array_shift($args);
  43. list($item['nid'], $item['teaser'], $item['hide_title']) = $args;
  44. }
  45. $output = array();
  46. if (isset($item['nid'])) {
  47. $node = node_load($item['nid']);
  48. if (!empty($node)) {
  49. if (node_access('view', $node)) {
  50. $buildmode = $item['teaser'] ? 'teaser' : 'full';
  51. $nstruct = node_view($node, $buildmode);
  52. if ($item['hide_title']) {
  53. $nstruct['#node']->title = NULL;
  54. }
  55. $output = $nstruct;
  56. }
  57. elseif (!$hide_empty) {
  58. $output = array('#markup' => theme('quicktabs_tab_access_denied', array('tab' => $item)));
  59. }
  60. }
  61. }
  62. return $output;
  63. }
  64. public function getAjaxKeys() {
  65. return array('nid', 'teaser', 'hide_title');
  66. }
  67. }