panels.api.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by Panels.
  5. */
  6. /**
  7. * Allow modules to provide their own caching mechanism for the display editor.
  8. *
  9. * @param string $argument
  10. * The second half of the cache key. Full key module:TASK_NAME:HANDLER_NAME
  11. * passed part: TASK_NAME:HANDLER_NAME
  12. * @param object $cache
  13. * The display to cache.
  14. */
  15. function hook_panels_cache_set($argument, $cache) {
  16. list($handler, $item) = _panels_mini_panels_cache_get($argument);
  17. $item->mini_panels_display_cache = $cache;
  18. $handler->edit_cache_set_key($item, $argument);
  19. }
  20. /**
  21. * Allow modules to provide their own caching mechanism for the display editor.
  22. *
  23. * @param string $argument
  24. * The second half of the cache key. Full key module:TASK_NAME:HANDLER_NAME
  25. * passed part: TASK_NAME:HANDLER_NAME
  26. *
  27. * @return stdClass|NULL
  28. * The cached display or NULL if the cache wasn't hit.
  29. */
  30. function hook_panels_cache_get($argument) {
  31. ctools_include('common', 'panels');
  32. list($handler, $item) = _panels_mini_panels_cache_get($argument);
  33. if (isset($item->mini_panels_display_cache)) {
  34. return $item->mini_panels_display_cache;
  35. }
  36. $cache = new stdClass();
  37. $cache->display = $item->display;
  38. $cache->display->context = ctools_context_load_contexts($item);
  39. $cache->display->cache_key = 'panels_mini:' . $argument;
  40. $cache->content_types = panels_common_get_allowed_types('panels_mini', $cache->display->context);
  41. $cache->display_title = TRUE;
  42. // @TODO support locking.
  43. $cache->locked = FALSE;
  44. return $cache;
  45. }
  46. /**
  47. * Allow modules to provide their own caching mechanism for the display editor.
  48. *
  49. * @param string $argument
  50. * The second half of the cache key. Full key module:TASK_NAME:HANDLER_NAME
  51. * passed part: TASK_NAME:HANDLER_NAME
  52. * @param object $cache
  53. * The display to cache.
  54. *
  55. * @return stdClass
  56. * The cached display.
  57. */
  58. function hook_panels_cache_save($argument, $cache) {
  59. list($handler, $item) = _panels_mini_panels_cache_get($argument);
  60. $item->display = $cache->display;
  61. panels_mini_save($item);
  62. $handler->edit_cache_clear($item);
  63. return $item;
  64. }
  65. /**
  66. * Allow modules to provide their own caching mechanism for the display editor.
  67. *
  68. * @param string $argument
  69. * The second half of the cache key. Full key module:TASK_NAME:HANDLER_NAME
  70. * passed part: TASK_NAME:HANDLER_NAME
  71. * @param object $cache
  72. * The cached display.
  73. */
  74. function hook_panels_cache_clear($argument, $cache) {
  75. list($handler, $item) = _panels_mini_panels_cache_get($argument);
  76. $handler->edit_cache_clear($item);
  77. }
  78. /**
  79. * Allow modules to adjust the rendering array of the panels dashboard.
  80. *
  81. * @param array $vars
  82. * The output variables.
  83. */
  84. function hook_panels_dashboard_blocks(&$vars) {
  85. $vars['links']['panels_node'] = array(
  86. 'title' => l(t('Panel node'), 'node/add/panel'),
  87. 'description' => t('Panel nodes are node content and appear in your searches, but are more limited than panel pages.'),
  88. 'weight' => -1,
  89. );
  90. }
  91. /**
  92. * Allow to alter the pane content to render.
  93. *
  94. * This happens after the keyword substitution.
  95. *
  96. * @param object $content
  97. * The content block to render.
  98. * @param object $pane
  99. * The pane object.
  100. * @param array $args
  101. * The display arguments.
  102. * @param array $contexts
  103. * Array with the used contexts.
  104. */
  105. function hook_panels_pane_content_alter($content, $pane, $args, $contexts) {
  106. // Don't display titles.
  107. unset($content->title);
  108. }
  109. /**
  110. * Allow modules to provide a mechanism to break locks.
  111. *
  112. * @param string $argument
  113. * The second half of the cache key. Full key module:TASK_NAME:HANDLER_NAME
  114. * passed part: TASK_NAME:HANDLER_NAME
  115. * @param object $cache
  116. * The cached display.
  117. */
  118. function hook_panels_edit_cache_break_lock($argument, $cache) {
  119. $cache->locked = FALSE;
  120. }
  121. /**
  122. * Fired before a panels display is rendered.
  123. *
  124. * Last chance to modify the panels display or add output before the keyword
  125. * substitution runs and the panels display is rendered.
  126. *
  127. * @param panels_display $panels_display
  128. * The panels display that will be rendered.
  129. * @param object $renderer
  130. * The renderer object that will be used to render.
  131. *
  132. * @return string
  133. * Additional output to add before the panels display.
  134. */
  135. function hook_panels_pre_render($panels_display, $renderer) {
  136. $translation = i18n_string_object_translate('panels_display_configuration', $panels_display);
  137. $panels_display->title = $translation->title;
  138. }
  139. /**
  140. * Fired after a panels display is rendered.
  141. *
  142. * Allow to add additional output after the output of the panels display.
  143. *
  144. * @param panels_display $panels_display
  145. * The rendered panels display.
  146. * @param object $renderer
  147. * The used renderer object.
  148. *
  149. * @return string
  150. * Additional output to add after the panels display.
  151. */
  152. function hook_panels_post_render($panels_display, $renderer) {
  153. return t('Output proudly sponsored by panels.');
  154. }
  155. /**
  156. * Fired before a new pane is inserted in the storage.
  157. *
  158. * @param object $pane
  159. * Pane that will be rendered.
  160. */
  161. function hook_panels_pane_insert($pane) {
  162. // Check if this pane has a custom title enabled.
  163. if (!empty($pane->configuration['override_title'])) {
  164. $translation_object = (object) array(
  165. 'pid' => $pane->pid,
  166. 'title' => $pane->configuration['override_title_text'],
  167. );
  168. $status = i18n_string_object_update('panels_pane_configuration', $translation_object);
  169. }
  170. }
  171. /**
  172. * Fired before a changed pane is updated in the storage.
  173. *
  174. * @param object $pane
  175. * Pane that will be rendered.
  176. */
  177. function hook_panels_pane_update($pane) {
  178. // Check if this pane has a custom title enabled.
  179. if (!empty($pane->configuration['override_title'])) {
  180. $translation_object = (object) array(
  181. 'pid' => $pane->pid,
  182. 'title' => $pane->configuration['override_title_text'],
  183. );
  184. $status = i18n_string_object_update('panels_pane_configuration', $translation_object);
  185. }
  186. }
  187. /**
  188. * Fired before a panel is rendered.
  189. *
  190. * Last chance to modify the pane before the keyword substitution runs and the
  191. * pane is rendered.
  192. *
  193. * @param object $pane
  194. * Pane that will be rendered.
  195. */
  196. function hook_panels_pane_prerender($pane) {
  197. // Check if this pane has a custom title enabled.
  198. if (!empty($pane->configuration['override_title'])) {
  199. $translation_object = (object) array(
  200. 'pid' => $pane->pid,
  201. 'title' => $pane->configuration['override_title_text'],
  202. );
  203. $translation_object = i18n_string_object_translate('panels_pane_configuration', $translation_object);
  204. $pane->configuration['override_title_text'] = $translation_object->title;
  205. }
  206. }
  207. /**
  208. * Fired before panes are deleted.
  209. *
  210. * @param array $pids
  211. * Array with the panel id's to delete.
  212. */
  213. function hook_panels_pane_delete($pids) {
  214. foreach ($pids as $pid) {
  215. // Create dummy pane with pid as property.
  216. $pane = (object) array('pid' => $pid);
  217. i18n_string_object_remove('panels_pane_configuration', $pane);
  218. }
  219. }
  220. /**
  221. * Fired after a display is saved.
  222. *
  223. * @param panels_display $display
  224. * The display to save.
  225. */
  226. function hook_panels_display_save($display) {
  227. i18n_string_object_update('display_configuration', $display);
  228. }
  229. /**
  230. * Fired before a display is deleted.
  231. *
  232. * @param int $did
  233. * Id of the display to delete.
  234. */
  235. function hook_panels_delete_display($did) {
  236. $uuid = db_select('panels_display')
  237. ->fields('panels_display', array('uuid'))
  238. ->condition('did', $did)
  239. ->execute()
  240. ->fetchColumn();
  241. $display = (object) array('uuid' => $uuid);
  242. i18n_string_object_remove('display_configuration', $display);
  243. }