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