function _panopoly_magic_render_preview_pane in Panopoly 7
Helper function to display the pane for showing previews in the add_content modal
1 call to _panopoly_magic_render_preview_pane()
- panopoly_magic_preprocess_panels_add_content_modal in modules/
panopoly/ panopoly_magic/ panopoly_magic.module - Preprocess the panels_add_content_modal() function to add the HTML for the preview
File
- modules/
panopoly/ panopoly_magic/ panopoly_magic.module, line 1665
Code
function _panopoly_magic_render_preview_pane(&$widget_vars, $renderer) {
$type = $widget_vars['type_name'];
$subtype = $widget_vars['subtype_name'];
$plugin = ctools_content_get_subtype($type, $subtype);
// Special case for reusable FPPs: by default we force the FPP callback so
// that the entity is rendered, and the custom callback or image isn't used.
// However, if a special key on the plugin subtype ('preview always') is set,
// then we won't force the FPP callback and the custom preview will always
// be used (regardless if it's a reusable FPP or not).
if ($type == 'fieldable_panels_pane' && !empty($plugin['entity_id']) && empty($plugin['preview always'])) {
$plugin['preview callback'] = 'panopoly_magic_preview_callback_fpp';
}
if (!empty($plugin['preview callback'])) {
$preview_callback = $plugin['preview callback'];
}
elseif (!empty($plugin['preview image'])) {
$preview_callback = 'panopoly_magic_preview_callback_image';
}
elseif ($type == 'fieldable_panels_pane') {
$preview_callback = 'panopoly_magic_preview_callback_fpp';
}
else {
$preview_callback = 'panopoly_magic_preview_callback_default';
}
if ($content = $preview_callback($type, $subtype, $plugin, $renderer)) {
// Permit the callback to return a render array.
if (is_array($content)) {
$content = drupal_render($content);
}
// Optionally strip JavaScript.
$strip_js = variable_get('panopoly_magic_strip_js_from_preview', 0);
if (!empty($strip_js) && !empty($content)) {
$content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
}
$widget_vars['preview'] = $content;
drupal_add_js(array(
'panopoly_magic' => array(
'pane_add_preview_type' => $type,
'pane_add_preview_subtype' => $subtype,
),
), 'setting');
}
}