You are here

function panopoly_magic_form_post_render_preview in Panopoly Magic 7

Add the preview to the form output.

It is done here so the form is fully processed.

1 call to panopoly_magic_form_post_render_preview()
panopoly_magic_ajax_update_preview in ./panopoly_magic.module
Ajax callback that just returns the rendered preview.
1 string reference to 'panopoly_magic_form_post_render_preview'
panopoly_magic_form_alter in ./panopoly_magic.module
Implements hook_form_alter()

File

./panopoly_magic.module, line 732

Code

function panopoly_magic_form_post_render_preview($output, $form) {
  extract($form['#panopoly_magic_preview_info']);

  // If no preview type was specified, render the pane as normal.
  if (empty($preview_callback)) {
    $preview_callback = 'ctools_content_render';
  }

  // If there is a 'destination', temporarily change the 'q' parameter so the
  // pane renders as if we are on that path.
  // @see https://www.drupal.org/node/2177417
  $original_path = $_GET['q'];
  if (!empty($_GET['destination'])) {
    $_GET['q'] = $_GET['destination'];
  }
  $content = $preview_callback($pane->type, $pane->subtype, $configuration, $keywords, $args, $context, $extra);

  // Restore the 'q' to its original value.
  $_GET['q'] = $original_path;
  if (!empty($content)) {

    // Wrap the widget content in the style plugin.
    if (!empty($style['render pane'])) {
      $content = theme($style['render pane'], array(
        'content' => $content,
        'pane' => $pane,
        'display' => $display,
        'style' => $style,
        'settings' => $pane->style['settings'],
      ));
    }
    else {
      $content = theme('panels_pane', array(
        'content' => $content,
        'pane' => $pane,
        'display' => $display,
      ));
    }
  }
  else {
    $content = t('[no preview]');
  }

  // Render the preview.
  return theme('panopoly_magic_preview', array(
    'title' => t('Preview'),
    'preview' => $content,
    'single' => TRUE,
  )) . $output;
}