panels_mini.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * @file
  4. * Contains the content type plugin for a mini panel. While this does not
  5. * need to be broken out into a .inc file, it's convenient that we do so
  6. * that we don't load code unnecessarily. Plus it demonstrates plugins
  7. * in modules other than Panels itself.
  8. */
  9. /**
  10. * Specially named hook. for .inc file. This looks a little silly due to the
  11. * redundancy, but that's really just because the content type shares a
  12. * name with the module.
  13. */
  14. function panels_mini_panels_mini_ctools_content_types() {
  15. return array(
  16. 'title' => t('Mini panels'),
  17. 'content type' => 'panels_mini_panels_mini_content_type_content_type',
  18. );
  19. }
  20. /**
  21. * Return each available mini panel available as a subtype.
  22. */
  23. function panels_mini_panels_mini_content_type_content_type($subtype_id, $plugin) {
  24. $mini = panels_mini_load($subtype_id);
  25. return _panels_mini_panels_mini_content_type_content_type($mini);
  26. }
  27. /**
  28. * Return each available mini panel available as a subtype.
  29. */
  30. function panels_mini_panels_mini_content_type_content_types($plugin) {
  31. $types = array();
  32. foreach (panels_mini_load_all() as $mini) {
  33. $type = _panels_mini_panels_mini_content_type_content_type($mini);
  34. if ($type) {
  35. $types[$mini->name] = $type;
  36. }
  37. }
  38. return $types;
  39. }
  40. /**
  41. * Return an info array describing a single mini panel.
  42. */
  43. function _panels_mini_panels_mini_content_type_content_type($mini) {
  44. if (empty($mini)) {
  45. // The mini panel is deleted or missing.
  46. return;
  47. }
  48. if (!empty($mini->disabled)) {
  49. return;
  50. }
  51. $title = filter_xss_admin($mini->admin_title);
  52. $type = array(
  53. 'title' => $title,
  54. // For now mini panels will just use the contrib block icon.
  55. 'icon' => 'icon_mini_panel.png',
  56. 'description' => $title,
  57. 'category' => !empty($mini->category) ? $mini->category : t('Mini panel'),
  58. );
  59. if (!empty($mini->requiredcontexts)) {
  60. $type['required context'] = array();
  61. foreach ($mini->requiredcontexts as $context) {
  62. $info = ctools_get_context($context['name']);
  63. // Check if the required context is actually required.
  64. if (!empty($context['optional'])) {
  65. $type['required context'][] = new ctools_context_optional($context['identifier'], $info['context name']);
  66. }
  67. else {
  68. $type['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
  69. }
  70. }
  71. }
  72. return $type;
  73. }
  74. /**
  75. * Render a mini panel called from a panels display.
  76. */
  77. function panels_mini_panels_mini_content_type_render($subtype, $conf, $panel_args, &$contexts) {
  78. static $viewing = array();
  79. $mini = panels_mini_load($subtype);
  80. if (!$mini) {
  81. return FALSE;
  82. }
  83. if (!empty($viewing[$mini->name])) {
  84. return FALSE;
  85. }
  86. // Load up any contexts we might be using.
  87. $context = ctools_context_match_required_contexts($mini->requiredcontexts, $contexts);
  88. $mini->context = $mini->display->context = ctools_context_load_contexts($mini, FALSE, $context);
  89. if (empty($mini) || !empty($mini->disabled)) {
  90. return;
  91. }
  92. $viewing[$mini->name] = TRUE;
  93. $mini->display->args = $panel_args;
  94. $mini->display->css_id = panels_mini_get_id($subtype);
  95. $mini->display->owner = $mini;
  96. // Unique ID of this mini.
  97. $mini->display->owner->id = $mini->name;
  98. $block = new stdClass();
  99. $block->module = 'panels_mini';
  100. $block->delta = $subtype;
  101. $block->content = panels_render_display($mini->display);
  102. $block->title = $mini->display->get_title();
  103. if (user_access('administer mini panels')) {
  104. $block->admin_links = array(
  105. array(
  106. 'title' => t('Configure mini panel'),
  107. 'href' => "admin/structure/mini-panels/list/$subtype/edit/content",
  108. 'query' => drupal_get_destination(),
  109. ),
  110. );
  111. }
  112. unset($viewing[$mini->name]);
  113. return $block;
  114. }
  115. /**
  116. * Edit form for the mini panel content type.
  117. */
  118. function panels_mini_panels_mini_content_type_edit_form($form, &$form_state) {
  119. // Empty form to ensure we have the override title + context gadgets.
  120. return $form;
  121. }
  122. /**
  123. * Provide the administrative title of a mini panel.
  124. */
  125. function panels_mini_panels_mini_content_type_admin_title($subtype, $conf) {
  126. $mini = panels_mini_load($subtype);
  127. if (!$mini) {
  128. return t('Deleted/missing mini panel @name', array('@name' => $subtype));
  129. }
  130. $title = filter_xss_admin($mini->admin_title);
  131. if (empty($title)) {
  132. $title = t('Untitled mini panel');
  133. }
  134. return $title;
  135. }
  136. /**
  137. * Callback to provide administrative info. Provide links to edit the mini
  138. * panel.
  139. */
  140. function panels_mini_panels_mini_content_type_admin_info($subtype, $conf) {
  141. $mini = panels_mini_load($subtype);
  142. if (!$mini) {
  143. return FALSE;
  144. }
  145. $block = new stdClass();
  146. $block->title = $mini->admin_title;
  147. $admin_pages = array(
  148. t('Settings') => 'basic',
  149. t('Context') => 'context',
  150. t('Layout') => 'layout',
  151. t('Content') => 'content',
  152. );
  153. $links = array();
  154. foreach ($admin_pages as $title => $tail) {
  155. $links[] = l($title, 'admin/structure/mini-panels/list/' . $subtype . '/edit/' . $tail, array('query' => drupal_get_destination()));
  156. }
  157. $block->content = theme('item_list', array('items' => $links));
  158. return $block;
  159. }