root / htmltest / sites / all / modules / panels / plugins / display_renderers / panels_renderer_standard.class.php @ c12e7e6a
1 | 85ad3d82 | Assos Assos | <?php
|
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * The standard render pipeline for a Panels display object.
|
||
5 | *
|
||
6 | * Given a fully-loaded panels_display object, this class will turn its
|
||
7 | * combination of layout, panes, and styles into HTML, invoking caching
|
||
8 | * appropriately along the way. Interacting with the renderer externally is
|
||
9 | * very simple - just pass it the display object and call the render() method:
|
||
10 | *
|
||
11 | * @code
|
||
12 | * // given that $display is a fully loaded Panels display object
|
||
13 | * $renderer = panels_get_renderer_handler('standard', $display)
|
||
14 | * $html_output = $renderer->render();
|
||
15 | * @endcode
|
||
16 | *
|
||
17 | * Internally, the render pipeline is divided into two phases, prepare and
|
||
18 | * render:
|
||
19 | * - The prepare phase transforms the skeletal data on the provided
|
||
20 | * display object into a structure that is expected by the render phase.
|
||
21 | * It is divided into a series of discrete sub-methods and operates
|
||
22 | * primarily by passing parameters, all with the intention of making
|
||
23 | * subclassing easier.
|
||
24 | * - The render phase relies primarily on data stored in the renderer object's
|
||
25 | * properties, presumably set in the prepare phase. It iterates through the
|
||
26 | * rendering of each pane, pane styling, placement in panel regions, region
|
||
27 | * styling, and finally the arrangement of rendered regions in the layout.
|
||
28 | * Caching, if in use, is triggered per pane, or on the entire display.
|
||
29 | *
|
||
30 | * In short: prepare builds conf, render renders conf. Subclasses should respect
|
||
31 | * this separation of responsibilities by adhering to these loose guidelines,
|
||
32 | * given a loaded display object:
|
||
33 | * - If your renderer needs to modify the datastructure representing what is
|
||
34 | * to be rendered (panes and their conf, styles, caching, etc.), it should
|
||
35 | * use the prepare phase.
|
||
36 | * - If your renderer needs to modify the manner in which that renderable
|
||
37 | * datastructure data is rendered, it should use the render phase.
|
||
38 | *
|
||
39 | * In the vast majority of use cases, this standard renderer will be sufficient
|
||
40 | * and need not be switched out/subclassed; style and/or layout plugins can
|
||
41 | * accommodate nearly every use case. If you think you might need a custom
|
||
42 | * renderer, consider the following criteria/examples:
|
||
43 | * - Some additional markup needs to be added to EVERY SINGLE panel.
|
||
44 | * - Given a full display object, just render one pane.
|
||
45 | * - Show a Panels admin interface.
|
||
46 | *
|
||
47 | * The system is almost functionally identical to the old procedural approach,
|
||
48 | * with some exceptions (@see panels_renderer_legacy for details). The approach
|
||
49 | * here differs primarily in its friendliness to tweaking in subclasses.
|
||
50 | */
|
||
51 | class panels_renderer_standard { |
||
52 | /**
|
||
53 | * The fully-loaded Panels display object that is to be rendered. "Fully
|
||
54 | * loaded" is defined as:
|
||
55 | * 1. Having been produced by panels_load_displays(), whether or this page
|
||
56 | * request or at some time in the past and the object was exported.
|
||
57 | * 2. Having had some external code attach context data ($display->context),
|
||
58 | * in the exact form expected by panes. Context matching is delicate,
|
||
59 | * typically relying on exact string matches, so special attention must
|
||
60 | * be taken.
|
||
61 | *
|
||
62 | * @var panels_display
|
||
63 | */
|
||
64 | var $display; |
||
65 | |||
66 | /**
|
||
67 | * An associative array of loaded plugins. Used primarily as a central
|
||
68 | * location for storing plugins that require additional loading beyond
|
||
69 | * reading the plugin definition, which is already statically cached by
|
||
70 | * ctools_get_plugins(). An example is layout plugins, which can optionally
|
||
71 | * have a callback that determines the set of panel regions available at
|
||
72 | * runtime.
|
||
73 | *
|
||
74 | * @var array
|
||
75 | */
|
||
76 | var $plugins = array(); |
||
77 | |||
78 | /**
|
||
79 | * A multilevel array of rendered data. The first level of the array
|
||
80 | * indicates the type of rendered data, typically with up to three keys:
|
||
81 | * 'layout', 'regions', and 'panes'. The relevant rendered data is stored as
|
||
82 | * the value for each of these keys as it is generated:
|
||
83 | * - 'panes' are an associative array of rendered output, keyed on pane id.
|
||
84 | * - 'regions' are an associative array of rendered output, keyed on region
|
||
85 | * name.
|
||
86 | * - 'layout' is the whole of the rendered output.
|
||
87 | *
|
||
88 | * @var array
|
||
89 | */
|
||
90 | var $rendered = array(); |
||
91 | |||
92 | /**
|
||
93 | * A multilevel array of data prepared for rendering. The first level of the
|
||
94 | * array indicates the type of prepared data. The standard renderer populates
|
||
95 | * and uses two top-level keys, 'panes' and 'regions':
|
||
96 | * - 'panes' are an associative array of pane objects to be rendered, keyed
|
||
97 | * on pane id and sorted into proper rendering order.
|
||
98 | * - 'regions' are an associative array of regions, keyed on region name,
|
||
99 | * each of which is itself an indexed array of pane ids in the order in
|
||
100 | * which those panes appear in that region.
|
||
101 | *
|
||
102 | * @var array
|
||
103 | */
|
||
104 | var $prepared = array(); |
||
105 | |||
106 | /**
|
||
107 | * Boolean state variable, indicating whether or not the prepare() method has
|
||
108 | * been run.
|
||
109 | *
|
||
110 | * This state is checked in panels_renderer_standard::render_layout() to
|
||
111 | * determine whether the prepare method should be automatically triggered.
|
||
112 | *
|
||
113 | * @var bool
|
||
114 | */
|
||
115 | var $prep_run = FALSE; |
||
116 | |||
117 | /**
|
||
118 | * The plugin that defines this handler.
|
||
119 | */
|
||
120 | var $plugin = FALSE; |
||
121 | |||
122 | /**
|
||
123 | * TRUE if this renderer is rendering in administrative mode
|
||
124 | * which will allow layouts to have extra functionality.
|
||
125 | *
|
||
126 | * @var bool
|
||
127 | */
|
||
128 | var $admin = FALSE; |
||
129 | |||
130 | /**
|
||
131 | * Where to add standard meta information. There are three possibilities:
|
||
132 | * - standard: Put the meta information in the normal location. Default.
|
||
133 | * - inline: Put the meta information directly inline. This will
|
||
134 | * not work for javascript.
|
||
135 | *
|
||
136 | * @var string
|
||
137 | */
|
||
138 | var $meta_location = 'standard'; |
||
139 | |||
140 | /**
|
||
141 | * Include rendered HTML prior to the layout.
|
||
142 | *
|
||
143 | * @var string
|
||
144 | */
|
||
145 | var $prefix = ''; |
||
146 | |||
147 | /**
|
||
148 | * Include rendered HTML after the layout.
|
||
149 | *
|
||
150 | * @var string
|
||
151 | */
|
||
152 | var $suffix = ''; |
||
153 | |||
154 | /**
|
||
155 | * Receive and store the display object to be rendered.
|
||
156 | *
|
||
157 | * This is a psuedo-constructor that should typically be called immediately
|
||
158 | * after object construction.
|
||
159 | *
|
||
160 | * @param array $plugin
|
||
161 | * The definition of the renderer plugin.
|
||
162 | * @param panels_display $display
|
||
163 | * The panels display object to be rendered.
|
||
164 | */
|
||
165 | function init($plugin, &$display) { |
||
166 | $this->plugin = $plugin; |
||
167 | $layout = panels_get_layout($display->layout); |
||
168 | $this->display = &$display; |
||
169 | $this->plugins['layout'] = $layout; |
||
170 | if (!isset($layout['regions'])) { |
||
171 | $this->plugins['layout']['regions'] = panels_get_regions($layout, $display); |
||
172 | } |
||
173 | |||
174 | if (empty($this->plugins['layout'])) { |
||
175 | watchdog('panels', "Layout: @layout couldn't been found, maybe the theme is disabled.", array('@layout' => $display->layout)); |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * Prepare the attached display for rendering.
|
||
181 | *
|
||
182 | * This is the outermost prepare method. It calls several sub-methods as part
|
||
183 | * of the overall preparation process. This compartmentalization is intended
|
||
184 | * to ease the task of modifying renderer behavior in child classes.
|
||
185 | *
|
||
186 | * If you override this method, it is important that you either call this
|
||
187 | * method via parent::prepare(), or manually set $this->prep_run = TRUE.
|
||
188 | *
|
||
189 | * @param mixed $external_settings
|
||
190 | * An optional parameter allowing external code to pass in additional
|
||
191 | * settings for use in the preparation process. Not used in the default
|
||
192 | * renderer, but included for interface consistency.
|
||
193 | */
|
||
194 | function prepare($external_settings = NULL) { |
||
195 | $this->prepare_panes($this->display->content); |
||
196 | $this->prepare_regions($this->display->panels, $this->display->panel_settings); |
||
197 | $this->prep_run = TRUE; |
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * Prepare the list of panes to be rendered, accounting for visibility/access
|
||
202 | * settings and rendering order.
|
||
203 | *
|
||
204 | * This method represents the standard approach for determining the list of
|
||
205 | * panes to be rendered that is compatible with all parts of the Panels
|
||
206 | * architecture. It first applies visibility & access checks, then sorts panes
|
||
207 | * into their proper rendering order, and returns the result as an array.
|
||
208 | *
|
||
209 | * Inheriting classes should override this method if that renderer needs to
|
||
210 | * regularly make additions to the set of panes that will be rendered.
|
||
211 | *
|
||
212 | * @param array $panes
|
||
213 | * An associative array of pane data (stdClass objects), keyed on pane id.
|
||
214 | * @return array
|
||
215 | * An associative array of panes to be rendered, keyed on pane id and sorted
|
||
216 | * into proper rendering order.
|
||
217 | */
|
||
218 | function prepare_panes($panes) { |
||
219 | ctools_include('content');
|
||
220 | // Use local variables as writing to them is very slightly faster
|
||
221 | $first = $normal = $last = array(); |
||
222 | |||
223 | // Prepare the list of panes to be rendered
|
||
224 | foreach ($panes as $pid => $pane) { |
||
225 | if (empty($this->admin)) { |
||
226 | // TODO remove in 7.x and ensure the upgrade path weeds out any stragglers; it's been long enough
|
||
227 | $pane->shown = !empty($pane->shown); // guarantee this field exists. |
||
228 | // If this pane is not visible to the user, skip out and do the next one
|
||
229 | if (!$pane->shown || !panels_pane_access($pane, $this->display)) { |
||
230 | continue;
|
||
231 | } |
||
232 | } |
||
233 | |||
234 | // If the pane's subtype is unique, get it so that
|
||
235 | // hook_ctools_content_subtype_alter() and/or
|
||
236 | // hook_ctools_block_info() will be called.
|
||
237 | if ($pane->type != $pane->subtype) { |
||
238 | $content_type = ctools_content_get_subtype($pane->type, $pane->subtype); |
||
239 | } |
||
240 | else {
|
||
241 | $content_type = ctools_get_content_type($pane->type); |
||
242 | } |
||
243 | |||
244 | // If this pane wants to render last, add it to the $last array. We allow
|
||
245 | // this because some panes need to be rendered after other panes,
|
||
246 | // primarily so they can do things like the leftovers of forms.
|
||
247 | if (!empty($content_type['render last'])) { |
||
248 | $last[$pid] = $pane; |
||
249 | } |
||
250 | // If it wants to render first, add it to the $first array. This is used
|
||
251 | // by panes that need to do some processing before other panes are
|
||
252 | // rendered.
|
||
253 | else if (!empty($content_type['render first'])) { |
||
254 | $first[$pid] = $pane; |
||
255 | } |
||
256 | // Otherwise, render it in the normal order.
|
||
257 | else {
|
||
258 | $normal[$pid] = $pane; |
||
259 | } |
||
260 | } |
||
261 | $this->prepared['panes'] = $first + $normal + $last; |
||
262 | return $this->prepared['panes']; |
||
263 | } |
||
264 | |||
265 | /**
|
||
266 | * Prepare the list of regions to be rendered.
|
||
267 | *
|
||
268 | * This method is primarily about properly initializing the style plugin that
|
||
269 | * will be used to render the region. This is crucial as regions cannot be
|
||
270 | * rendered without a style plugin (in keeping with Panels' philosophy of
|
||
271 | * hardcoding none of its output), but for most regions no style has been
|
||
272 | * explicitly set. The logic here is what accommodates that situation:
|
||
273 | * - If a region has had its style explicitly set, then we fetch that plugin
|
||
274 | * and continue.
|
||
275 | * - If the region has no explicit style, but a style was set at the display
|
||
276 | * level, then inherit the style from the display.
|
||
277 | * - If neither the region nor the dispay have explicitly set styles, then
|
||
278 | * fall back to the hardcoded 'default' style, a very minimal style.
|
||
279 | *
|
||
280 | * The other important task accomplished by this method is ensuring that even
|
||
281 | * regions without any panes are still properly prepared for the rendering
|
||
282 | * process. This is essential because the way Panels loads display objects
|
||
283 | * (@see panels_load_displays) results only in a list of regions that
|
||
284 | * contain panes - not necessarily all the regions defined by the layout
|
||
285 | * plugin, which can only be determined by asking the plugin at runtime. This
|
||
286 | * method consults that retrieved list of regions and prepares all of those,
|
||
287 | * ensuring none are inadvertently skipped.
|
||
288 | *
|
||
289 | * @param array $region_pane_list
|
||
290 | * An associative array of pane ids, keyed on the region to which those pids
|
||
291 | * are assigned. In the default case, this is $display->panels.
|
||
292 | * @param array $settings
|
||
293 | * All known region style settings, including both the top-level display's
|
||
294 | * settings (if any) and all region-specific settings (if any).
|
||
295 | * @return array
|
||
296 | * An array of regions prepared for rendering.
|
||
297 | */
|
||
298 | function prepare_regions($region_pane_list, $settings) { |
||
299 | // Initialize defaults to be used for regions without their own explicit
|
||
300 | // settings. Use display settings if they exist, else hardcoded defaults.
|
||
301 | $default = array( |
||
302 | 'style' => panels_get_style(!empty($settings['style']) ? $settings['style'] : 'default'), |
||
303 | 'style settings' => isset($settings['style_settings']['default']) ? $settings['style_settings']['default'] : array(), |
||
304 | ); |
||
305 | |||
306 | $regions = array(); |
||
307 | if (empty($settings)) { |
||
308 | // No display/panel region settings exist, init all with the defaults.
|
||
309 | foreach ($this->plugins['layout']['regions'] as $region_id => $title) { |
||
310 | // Ensure this region has at least an empty panes array.
|
||
311 | $panes = !empty($region_pane_list[$region_id]) ? $region_pane_list[$region_id] : array(); |
||
312 | |||
313 | $regions[$region_id] = $default; |
||
314 | $regions[$region_id]['pids'] = $panes; |
||
315 | } |
||
316 | } |
||
317 | else {
|
||
318 | // Some settings exist; iterate through each region and set individually.
|
||
319 | foreach ($this->plugins['layout']['regions'] as $region_id => $title) { |
||
320 | // Ensure this region has at least an empty panes array.
|
||
321 | $panes = !empty($region_pane_list[$region_id]) ? $region_pane_list[$region_id] : array(); |
||
322 | if (empty($settings[$region_id]['style']) || $settings[$region_id]['style'] == -1) { |
||
323 | $regions[$region_id] = $default; |
||
324 | } |
||
325 | else {
|
||
326 | $regions[$region_id]['style'] = panels_get_style($settings[$region_id]['style']); |
||
327 | $regions[$region_id]['style settings'] = isset($settings['style_settings'][$region_id]) ? $settings['style_settings'][$region_id] : array(); |
||
328 | } |
||
329 | $regions[$region_id]['pids'] = $panes; |
||
330 | } |
||
331 | } |
||
332 | |||
333 | $this->prepared['regions'] = $regions; |
||
334 | return $this->prepared['regions']; |
||
335 | } |
||
336 | |||
337 | /**
|
||
338 | * Build inner content, then hand off to layout-specified theme function for
|
||
339 | * final render step.
|
||
340 | *
|
||
341 | * This is the outermost method in the Panels render pipeline. It calls the
|
||
342 | * inner methods, which return a content array, which is in turn passed to the
|
||
343 | * theme function specified in the layout plugin.
|
||
344 | *
|
||
345 | * @return string
|
||
346 | * Themed & rendered HTML output.
|
||
347 | */
|
||
348 | function render() { |
||
349 | // Let the display refer back to the renderer.
|
||
350 | $this->display->renderer_handler = $this; |
||
351 | |||
352 | // Attach out-of-band data first.
|
||
353 | $this->add_meta();
|
||
354 | |||
355 | if (empty($this->display->cache['method']) || !empty($this->display->skip_cache)) { |
||
356 | return $this->render_layout(); |
||
357 | } |
||
358 | else {
|
||
359 | $cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context); |
||
360 | if ($cache === FALSE) { |
||
361 | $cache = new panels_cache_object(); |
||
362 | $cache->set_content($this->render_layout()); |
||
363 | panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context); |
||
364 | } |
||
365 | return $cache->content; |
||
366 | } |
||
367 | } |
||
368 | |||
369 | /**
|
||
370 | * Perform display/layout-level render operations.
|
||
371 | *
|
||
372 | * This method triggers all the inner pane/region rendering processes, passes
|
||
373 | * that to the layout plugin's theme callback, and returns the rendered HTML.
|
||
374 | *
|
||
375 | * If display-level caching is enabled and that cache is warm, this method
|
||
376 | * will not be called.
|
||
377 | *
|
||
378 | * @return string
|
||
379 | * The HTML string representing the entire rendered, themed panel.
|
||
380 | */
|
||
381 | function render_layout() { |
||
382 | if (empty($this->prep_run)) { |
||
383 | $this->prepare();
|
||
384 | } |
||
385 | $this->render_panes();
|
||
386 | $this->render_regions();
|
||
387 | |||
388 | if ($this->admin && !empty($this->plugins['layout']['admin theme'])) { |
||
389 | $theme = $this->plugins['layout']['admin theme']; |
||
390 | } |
||
391 | else {
|
||
392 | $theme = $this->plugins['layout']['theme']; |
||
393 | } |
||
394 | |||
395 | $this->rendered['layout'] = theme($theme, array('css_id' => check_plain($this->display->css_id), 'content' => $this->rendered['regions'], 'settings' => $this->display->layout_settings, 'display' => $this->display, 'layout' => $this->plugins['layout'], 'renderer' => $this)); |
||
396 | return $this->prefix . $this->rendered['layout'] . $this->suffix; |
||
397 | } |
||
398 | |||
399 | /**
|
||
400 | * Attach out-of-band page metadata (e.g., CSS and JS).
|
||
401 | *
|
||
402 | * This must be done before render, because panels-within-panels must have
|
||
403 | * their CSS added in the right order: inner content before outer content.
|
||
404 | */
|
||
405 | function add_meta() { |
||
406 | if (!empty($this->plugins['layout']['css'])) { |
||
407 | if (file_exists(path_to_theme() . '/' . $this->plugins['layout']['css'])) { |
||
408 | $this->add_css(path_to_theme() . '/' . $this->plugins['layout']['css']); |
||
409 | } |
||
410 | else {
|
||
411 | $this->add_css($this->plugins['layout']['path'] . '/' . $this->plugins['layout']['css']); |
||
412 | } |
||
413 | } |
||
414 | |||
415 | if ($this->admin && isset($this->plugins['layout']['admin css'])) { |
||
416 | $this->add_css($this->plugins['layout']['path'] . '/' . $this->plugins['layout']['admin css']); |
||
417 | } |
||
418 | } |
||
419 | |||
420 | /**
|
||
421 | * Add CSS information to the renderer.
|
||
422 | *
|
||
423 | * To facilitate previews over Views, CSS can now be added in a manner
|
||
424 | * that does not necessarily mean just using drupal_add_css. Therefore,
|
||
425 | * during the panel rendering process, this method can be used to add
|
||
426 | * css and make certain that ti gets to the proper location.
|
||
427 | *
|
||
428 | * The arguments should exactly match drupal_add_css().
|
||
429 | *
|
||
430 | * @see drupal_add_css
|
||
431 | */
|
||
432 | function add_css($filename) { |
||
433 | switch ($this->meta_location) { |
||
434 | case 'standard': |
||
435 | drupal_add_css($filename);
|
||
436 | break;
|
||
437 | case 'inline': |
||
438 | $url = base_path() . $filename; |
||
439 | $this->prefix .= '<link type="text/css" rel="stylesheet" href="' . $url . '" />'."\n"; |
||
440 | break;
|
||
441 | } |
||
442 | } |
||
443 | |||
444 | /**
|
||
445 | * Render all prepared panes, first by dispatching to their plugin's render
|
||
446 | * callback, then handing that output off to the pane's style plugin.
|
||
447 | *
|
||
448 | * @return array
|
||
449 | * The array of rendered panes, keyed on pane pid.
|
||
450 | */
|
||
451 | function render_panes() { |
||
452 | ctools_include('content');
|
||
453 | |||
454 | // First, render all the panes into little boxes.
|
||
455 | $this->rendered['panes'] = array(); |
||
456 | foreach ($this->prepared['panes'] as $pid => $pane) { |
||
457 | $content = $this->render_pane($pane); |
||
458 | if ($content) { |
||
459 | $this->rendered['panes'][$pid] = $content; |
||
460 | } |
||
461 | } |
||
462 | return $this->rendered['panes']; |
||
463 | } |
||
464 | |||
465 | /**
|
||
466 | * Render a pane using its designated style.
|
||
467 | *
|
||
468 | * This method also manages 'title pane' functionality, where the title from
|
||
469 | * an individual pane can be bubbled up to take over the title for the entire
|
||
470 | * display.
|
||
471 | *
|
||
472 | * @param stdClass $pane
|
||
473 | * A Panels pane object, as loaded from the database.
|
||
474 | */
|
||
475 | function render_pane(&$pane) { |
||
476 | $content = $this->render_pane_content($pane); |
||
477 | if ($this->display->hide_title == PANELS_TITLE_PANE && !empty($this->display->title_pane) && $this->display->title_pane == $pane->pid) { |
||
478 | |||
479 | // If the user selected to override the title with nothing, and selected
|
||
480 | // this as the title pane, assume the user actually wanted the original
|
||
481 | // title to bubble up to the top but not actually be used on the pane.
|
||
482 | if (empty($content->title) && !empty($content->original_title)) { |
||
483 | $this->display->stored_pane_title = $content->original_title; |
||
484 | } |
||
485 | else {
|
||
486 | $this->display->stored_pane_title = !empty($content->title) ? $content->title : ''; |
||
487 | } |
||
488 | } |
||
489 | |||
490 | if (!empty($content->content)) { |
||
491 | if (!empty($pane->style['style'])) { |
||
492 | $style = panels_get_style($pane->style['style']); |
||
493 | |||
494 | if (isset($style) && isset($style['render pane'])) { |
||
495 | $output = theme($style['render pane'], array('content' => $content, 'pane' => $pane, 'display' => $this->display, 'style' => $style, 'settings' => $pane->style['settings'])); |
||
496 | |||
497 | // This could be null if no theme function existed.
|
||
498 | if (isset($output)) { |
||
499 | return $output; |
||
500 | } |
||
501 | } |
||
502 | } |
||
503 | |||
504 | // fallback
|
||
505 | return theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $this->display)); |
||
506 | } |
||
507 | } |
||
508 | |||
509 | /**
|
||
510 | * Render the interior contents of a single pane.
|
||
511 | *
|
||
512 | * This method retrieves pane content and produces a ready-to-render content
|
||
513 | * object. It also manages pane-specific caching.
|
||
514 | *
|
||
515 | * @param stdClass $pane
|
||
516 | * A Panels pane object, as loaded from the database.
|
||
517 | * @return stdClass $content
|
||
518 | * A renderable object, containing a subject, content, etc. Based on the
|
||
519 | * renderable objects used by the block system.
|
||
520 | */
|
||
521 | function render_pane_content(&$pane) { |
||
522 | ctools_include('context');
|
||
523 | // TODO finally safe to remove this check?
|
||
524 | if (!is_array($this->display->context)) { |
||
525 | watchdog('panels', 'renderer::render_pane_content() hit with a non-array for the context', $this->display, WATCHDOG_DEBUG); |
||
526 | $this->display->context = array(); |
||
527 | } |
||
528 | |||
529 | $content = FALSE; |
||
530 | $caching = !empty($pane->cache['method']) && empty($this->display->skip_cache); |
||
531 | if ($caching && ($cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context, $pane))) { |
||
532 | $content = $cache->content; |
||
533 | } |
||
534 | else {
|
||
535 | if ($caching) { |
||
536 | // This is created before rendering so that calls to drupal_add_js
|
||
537 | // and drupal_add_css will be captured.
|
||
538 | $cache = new panels_cache_object(); |
||
539 | } |
||
540 | |||
541 | $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $this->display->args, $this->display->context); |
||
542 | |||
543 | if (empty($content)) { |
||
544 | return;
|
||
545 | } |
||
546 | |||
547 | foreach (module_implements('panels_pane_content_alter') as $module) { |
||
548 | $function = $module . '_panels_pane_content_alter'; |
||
549 | $function($content, $pane, $this->display->args, $this->display->context, $this, $this->display); |
||
550 | } |
||
551 | if ($caching && isset($cache)) { |
||
552 | $cache->set_content($content); |
||
553 | panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context, $pane); |
||
554 | $content = $cache->content; |
||
555 | } |
||
556 | } |
||
557 | |||
558 | // Pass long the css_id that is usually available.
|
||
559 | if (!empty($pane->css['css_id'])) { |
||
560 | $content->css_id = check_plain($pane->css['css_id']); |
||
561 | } |
||
562 | |||
563 | // Pass long the css_class that is usually available.
|
||
564 | if (!empty($pane->css['css_class'])) { |
||
565 | $content->css_class = check_plain($pane->css['css_class']); |
||
566 | } |
||
567 | |||
568 | return $content; |
||
569 | } |
||
570 | |||
571 | /**
|
||
572 | * Render all prepared regions, placing already-rendered panes into their
|
||
573 | * appropriate positions therein.
|
||
574 | *
|
||
575 | * @return array
|
||
576 | * An array of rendered panel regions, keyed on the region name.
|
||
577 | */
|
||
578 | function render_regions() { |
||
579 | $this->rendered['regions'] = array(); |
||
580 | |||
581 | // Loop through all panel regions, put all panes that belong to the current
|
||
582 | // region in an array, then render the region. Primarily this ensures that
|
||
583 | // the panes are arranged in the proper order.
|
||
584 | $content = array(); |
||
585 | foreach ($this->prepared['regions'] as $region_id => $conf) { |
||
586 | $region_panes = array(); |
||
587 | foreach ($conf['pids'] as $pid) { |
||
588 | // Only include panes for region rendering if they had some output.
|
||
589 | if (!empty($this->rendered['panes'][$pid])) { |
||
590 | $region_panes[$pid] = $this->rendered['panes'][$pid]; |
||
591 | } |
||
592 | } |
||
593 | $this->rendered['regions'][$region_id] = $this->render_region($region_id, $region_panes); |
||
594 | } |
||
595 | |||
596 | return $this->rendered['regions']; |
||
597 | } |
||
598 | |||
599 | /**
|
||
600 | * Render a single panel region.
|
||
601 | *
|
||
602 | * Primarily just a passthrough to the panel region rendering callback
|
||
603 | * specified by the style plugin that is attached to the current panel region.
|
||
604 | *
|
||
605 | * @param $region_id
|
||
606 | * The ID of the panel region being rendered
|
||
607 | * @param $panes
|
||
608 | * An array of panes that are assigned to the panel that's being rendered.
|
||
609 | *
|
||
610 | * @return string
|
||
611 | * The rendered, HTML string output of the passed-in panel region.
|
||
612 | */
|
||
613 | function render_region($region_id, $panes) { |
||
614 | $style = $this->prepared['regions'][$region_id]['style']; |
||
615 | $style_settings = $this->prepared['regions'][$region_id]['style settings']; |
||
616 | |||
617 | // Retrieve the pid (can be a panel page id, a mini panel id, etc.), this
|
||
618 | // might be used (or even necessary) for some panel display styles.
|
||
619 | // TODO: Got to fix this to use panel page name instead of pid, since pid is
|
||
620 | // no longer guaranteed. This needs an API to be able to set the final id.
|
||
621 | $owner_id = 0; |
||
622 | if (isset($this->display->owner) && is_object($this->display->owner) && isset($this->display->owner->id)) { |
||
623 | $owner_id = $this->display->owner->id; |
||
624 | } |
||
625 | |||
626 | $output = theme($style['render region'], array('display' => $this->display, 'owner_id' => $owner_id, 'panes' => $panes, 'settings' => $style_settings, 'region_id' => $region_id, 'style' => $style)); |
||
627 | return $output; |
||
628 | } |
||
629 | } |