function panopoly_magic_preprocess_panels_add_content_modal in Panopoly 7
Preprocess the panels_add_content_modal() function to add the HTML for the preview
File
- modules/
panopoly/ panopoly_magic/ panopoly_magic.module, line 1715
Code
function panopoly_magic_preprocess_panels_add_content_modal(&$vars) {
// Generate the pane preview
if (!empty($vars['categories'][$vars['category']]['content'])) {
$use_preview = variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT);
if ($use_preview == PANOPOLY_ADD_PREVIEW_DISABLED) {
return;
}
// Generate the preview for the single widget if requested.
if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
$query = drupal_get_query_parameters();
$type_name = !empty($query['type_name']) ? $query['type_name'] : '';
$sub_type = !empty($query['subtype_name']) ? $query['subtype_name'] : '';
$widget_vars = array(
'type_name' => $type_name,
'subtype_name' => $sub_type,
);
_panopoly_magic_render_preview_pane($widget_vars, $vars['renderer']);
$vars['column_count'] = 1;
$vars['preview_single'] = isset($widget_vars['preview']) ? $widget_vars['preview'] : '';
$vars['preview_single_title'] = '';
foreach ($vars['categories'][$vars['category']]['content'] as $key => $widget_vars) {
if ($widget_vars['type_name'] == $type_name && $widget_vars['subtype_name'] == $sub_type) {
$vars['preview_single_title'] = $key;
break;
}
}
}
// Process each widget option, either adding the preview itself or a link to generate it.
foreach ($vars['categories'][$vars['category']]['content'] as $key => &$widget_vars) {
$query = drupal_get_query_parameters();
$preview_panes = !empty($query['preview_panes']) ? explode(',', $query['preview_panes']) : array();
// Determine if we should show a preview for this pane.
if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
// Convert the link to generate a preview of itself.
$options = array(
'query' => array(
'panopoly_magic_preview' => _panopoly_magic_add_content_preview_mode_name($use_preview),
'type_name' => $widget_vars['type_name'],
'subtype_name' => $widget_vars['subtype_name'],
),
'attributes' => array(
'class' => array(
'use-ajax button',
),
),
'html' => TRUE,
);
$widget_vars['title'] = l(t('<span class="element-invisible">Preview</span> !widget <span class="element-invisible">widget</span>', array(
'!widget' => filter_xss_admin($widget_vars['title']),
)), current_path(), $options);
}
elseif ($use_preview == PANOPOLY_ADD_PREVIEW_AUTOMATIC || in_array($widget_vars['subtype_name'], $preview_panes)) {
_panopoly_magic_render_preview_pane($widget_vars, $vars['renderer']);
}
else {
// If we can't preview then generate a preview link.
$preview = empty($query['preview_panes']) ? $widget_vars['subtype_name'] : $query['preview_panes'] . ',' . $widget_vars['subtype_name'];
$options = array(
'query' => array(
'panopoly_magic_preview' => _panopoly_magic_add_content_preview_mode_name($use_preview),
'preview_panes' => $preview,
),
'attributes' => array(
'class' => array(
'use-ajax button',
),
'title' => t('Preview @widget widget', array(
'@widget' => $key,
)),
),
'html' => TRUE,
);
$widget_vars['preview'] = '<div class="modal-content-preview-button">' . l(t('Preview <span class="element-invisible">!widget widget</span>', array(
'!widget' => filter_xss_admin($key),
)), current_path(), $options) . '</div>';
}
}
}
}