From c397854f713d966467f820ab49f355779a4ae9bf Mon Sep 17 00:00:00 2001
From: William Hearn <sylus1984@gmail.com>
Date: Fri, 28 Nov 2014 13:38:54 -0500
Subject: [PATCH] Fix for panels magic.

---
 css/panopoly-modal.css |  84 ++++++++++++++++++-----
 panopoly_magic.module  | 183 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 200 insertions(+), 67 deletions(-)

diff --git a/css/panopoly-modal.css b/css/panopoly-modal.css
index 1e4b663..f273dd4 100644
--- a/css/panopoly-modal.css
+++ b/css/panopoly-modal.css
@@ -93,7 +93,7 @@
   padding: 0 12px;
 }
 
-#modalContent .panels-add-content-modal a.panels-modal-add-category:active, 
+#modalContent .panels-add-content-modal a.panels-modal-add-category:active,
 #modalContent .panels-add-content-modal a.panels-modal-add-category.active {
   border: 1px solid #CECECA;
   border-right: none;
@@ -229,7 +229,7 @@
 #modal-content fieldset.widget-preview-single .fieldset-wrapper .panopoly-spotlight img {
   width: 100%;
 }
-  
+
 #modal-content fieldset legend {
   background: #dbdbdb;
   border: 1px solid #ccc;
@@ -252,17 +252,17 @@
   -webkit-border-top-right-radius: 4px;
   border-top-right-radius: 4px;
 }
-  
+
 #modal-content fieldset.widget-preview legend {
   -moz-border-radius-topright: 0;
   -webkit-border-top-right-radius: 0;
   border-top-right-radius: 0;
 }
-  
+
 #modal-content .fieldset-legend {
   font: bold 12px/1.5em 'Open Sans', 'Lucida Sans', 'Lucida Grande', Verdana, sans-serif;
 }
-  
+
 #modal-content fieldset.collapsed legend {
   -moz-border-radius: 4px;
   -webkit-border-radius: 4px;
@@ -278,7 +278,7 @@
 #modal-content fieldset legend a:active {
   color: #000;
 }
-  
+
 #modal-content .fieldset-wrapper {
   padding: 0 10px;
   margin-top: 2.25em;
@@ -293,7 +293,7 @@
   overflow-x: hidden;
 }
 
-#modal-content .widget-preview .fieldset-wrapper table tr.even td, 
+#modal-content .widget-preview .fieldset-wrapper table tr.even td,
 #modal-content .widget-preview .fieldset-wrapper table tr.odd td {
   padding: 3px 5px;
 }
@@ -409,14 +409,14 @@
 /**
  * Misc Modal Stylings
  */
-#modal-content .form-type-textarea .form-type-select, 
+#modal-content .form-type-textarea .form-type-select,
 #modal-content .field-type-text-long .form-type-select {
   float: right;
   margin-top: 5px;
   margin-bottom: 5px;
 }
 
-#modal-content .form-type-textarea .form-type-select label, 
+#modal-content .form-type-textarea .form-type-select label,
 #modal-content .field-type-text-long .form-type-select label {
   float: left;
   margin-right: .5em;
@@ -435,7 +435,7 @@
   font-size: 1em;
 }
 
-#modal-content .widget-preview-title .content-type-button img, 
+#modal-content .widget-preview-title .content-type-button img,
 #modal-content .panels-add-content-modal > .panels-modal-add-category {
   display: none;
 }
@@ -448,19 +448,19 @@
   border: none;
 }
 
-#modal-content .widget-preview .fieldset-wrapper table img, 
+#modal-content .widget-preview .fieldset-wrapper table img,
 #modal-content .widget-preview .panopoly-image-featured {
   width: 100%;
 }
 
-.pane-content .create-links, 
-.pane-categories .categories-links, 
-.pane-menus .menu-links, 
+.pane-content .create-links,
+.pane-categories .categories-links,
+.pane-menus .menu-links,
 .pane-users .user-links {
   float: right;
 }
 
-#modalContent .panels-add-content-modal a.panels-modal-add-category:hover, 
+#modalContent .panels-add-content-modal a.panels-modal-add-category:hover,
 #modalContent .panels-section-column-categories .content-type-button a:hover,
 #modalContent .panels-add-content-modal a.panels-modal-add-category:focus,
 #modalContent .panels-section-column-categories .content-type-button a:focus {
@@ -508,7 +508,7 @@
   left top,
   color-stop(0, #E9EAEC),
   color-stop(1, #FAFAFA)
-  ); 
+  );
   -webkit-box-shadow: 0 3px 3px 0 #d2d2d2;
   -moz-box-shadow: 0 3px 3px 0 #d2d2d2;
   box-shadow: 0 3px 3px 0 #d2d2d2;
@@ -550,3 +550,55 @@
   -moz-box-shadow: 0 0 0 0 #fff;
   box-shadow: 0 0 0 0 #fff;
 }
+
+#modal-content .content-wrapper {
+  position: relative;
+  padding: 5px 0px;
+}
+
+#modal-content .content-wrapper .content-type-button {
+  position: absolute;
+  right: 10px;
+  top: 50%; margin-top: -10px;
+  opacity: 0;
+}
+
+#modal-content .content-wrapper .content-type-button a {
+  background: #999;
+  float: left;
+  color: white;
+  padding: 5px 10px;
+}
+
+#modal-content .content-wrapper .content-type-button a img {
+  display: none;
+}
+
+#modal-content .content-wrapper .content-type-button a span {
+  margin: 0;
+  padding: 0;
+}
+
+#modal-content .content-wrapper .content-type-button a:hover {
+  background: #2fa6e5;
+}
+
+#modal-content .content-wrapper .fieldset-legend a {
+  background: transparent;
+  border: none;
+  color: #666 !important;
+  text-shadow: none;
+  margin: 0;
+  padding: 0px 50px 0px 0px;
+  text-align: left;
+  width: 100%;
+  cursor: pointer;
+}
+
+#modal-content .content-wrapper .fieldset-legend a:hover {
+  color: #000 !important;
+}
+
+#modal-content .content-wrapper:hover .content-type-button {
+  opacity: 1;
+}
diff --git a/panopoly_magic.module b/panopoly_magic.module
index c5f15b0..a7d0158 100644
--- a/panopoly_magic.module
+++ b/panopoly_magic.module
@@ -4,6 +4,7 @@ include_once('panopoly_magic.features.inc');
 define('PANOPOLY_ADD_PREVIEW_MANUAL', 0);
 define('PANOPOLY_ADD_PREVIEW_AUTOMATIC', 1);
 define('PANOPOLY_ADD_PREVIEW_DISABLED', 2);
+define('PANOPOLY_ADD_PREVIEW_SINGLE', 3);
 define('PANOPOLY_ADD_PREVIEW_DEFAULT', PANOPOLY_ADD_PREVIEW_AUTOMATIC);
 
 /**
@@ -109,7 +110,7 @@ function panopoly_magic_theme($existing, $type, $theme, $path) {
  * Implements hook_menu_alter().
  */
 function panopoly_magic_menu_alter(&$items) {
-  // Include entity_field.inc from ctools to ensure that files can be properly removed 
+  // Include entity_field.inc from ctools to ensure that files can be properly removed
   // from within the panelizer edit forms.
   $items['file/ajax']['file'] = 'entity_field.inc';
   $items['file/ajax']['file path'] = drupal_get_path('module', 'ctools') . '/plugins/content_types/entity_context';
@@ -141,6 +142,7 @@ function panopoly_magic_configure_form($form, &$form_state) {
     '#options' => array(
       PANOPOLY_ADD_PREVIEW_AUTOMATIC => 'Automatic',
       PANOPOLY_ADD_PREVIEW_MANUAL => 'Manual',
+      PANOPOLY_ADD_PREVIEW_SINGLE => 'Single',
       PANOPOLY_ADD_PREVIEW_DISABLED => 'Disabled',
     ),
     '#default_value' => variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT),
@@ -254,7 +256,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
       // Run entity information through standard submission form if this is a new or updated object
       // Update the pane settngs with the VID afterwards
       if (!$form_state['entity']->reusable || $form_state['op'] != 'add' || $form_state['rebuild'] == TRUE) {
-        // Process the entity to create a preview. Set the FPID to be the correct version. We need to 
+        // Process the entity to create a preview. Set the FPID to be the correct version. We need to
         // generate a fake set of values to avoid notices from FPP as per http://drupal.org/node/1791734.
         $default_values = array(
           'language' => '',
@@ -294,7 +296,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
       'panels_edit_style_settings_form',
     );
     $configuration = ($form_state['rebuild'] && (strpos($form_id, 'content_type_edit_form') || in_array($form_id, $configuration_ids))) ? array_merge($pane->configuration, $form_state['input']) : $pane->configuration;
-   
+
     $keywords = array();
     $args = array();
     if (!empty($form_state['contexts'])) {
@@ -306,7 +308,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
     else {
       $context = array();
     }
-   
+
     // Special case for panelizer fields being edited through the IPE. For some reason images are not being fully loaded
     if (!empty($pane->configuration['formatter']) && $pane->configuration['formatter'] == 'image') {
       list($entity_type, $field_name) = explode(':', $pane->subtype);
@@ -377,7 +379,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
     // Convert any other #ajax enabled buttons to use system/panopoly-magic.
     _panopoly_magic_add_path_to_ajax($form);
   }
-  
+
   /**
    * Globally improve the buttons for the Chaos Tools Content Type Settings Forms
    */
@@ -404,7 +406,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
   );
 
   if (in_array($form_id, $forms_to_improve)) {
-  
+
     // Grab child elements and create the fieldset.
     $children = element_children($form);
     if (count($children) > 1) {
@@ -423,7 +425,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) {
       }
 
       // Don't show the context when it is the only one
-      if (!empty($form['general_settings']['context']) && count($form['general_settings']['context']['#options']) == 1) { 
+      if (!empty($form['general_settings']['context']) && count($form['general_settings']['context']['#options']) == 1) {
         $form['general_settings']['context']['#type'] = 'value';
         $form['general_settings']['context']['#value'] = $form['general_settings']['context']['#default_value'];
       }
@@ -516,7 +518,7 @@ function panopoly_magic_autosubmit_configure(&$element) {
   }
 
   $children = element_children($element);
-  
+
   if (!empty($children) && is_array($children)) {
     foreach ($children as $child) {
       panopoly_magic_autosubmit_configure($element[$child]);
@@ -524,16 +526,16 @@ function panopoly_magic_autosubmit_configure(&$element) {
   }
 }
 
-/** 
+/**
  * Implementation of hook_form_FORM_ID_alter()
  */
 function panopoly_magic_form_fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form_alter(&$form, &$form_state, $form_id) {
 
-  // Setup the live preview 
+  // Setup the live preview
   if (variable_get('panopoly_magic_live_preview', 1)) {
     panopoly_magic_autosubmit_configure($form);
 
-    // Special case exclusions for tablefield specific elements. 
+    // Special case exclusions for tablefield specific elements.
     if ($form_state['entity']->bundle == 'table') {
       $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#attributes']['class'] = array('ctools-auto-submit-exclude');
       $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#attributes']['class'] = array('ctools-auto-submit-exclude');
@@ -560,7 +562,7 @@ function panopoly_magic_form_fieldable_panels_panes_fieldable_panels_pane_conten
   if (!empty($form['widget_settings']['title'])) {
     $form['widget_settings']['title']['#size'] = '';
   }
-  
+
   // Improving the link Options
   if (!empty($form['widget_settings']['link'])) {
     $form['widget_settings']['link']['path']['#size'] = '';
@@ -569,7 +571,7 @@ function panopoly_magic_form_fieldable_panels_panes_fieldable_panels_pane_conten
     $form['widget_settings']['link']['path']['#description'] = t('The URL or Drupal path from which to build the link.');
     $form['widget_settings']['link']['link']['#description'] = '';
   }
-  
+
   // Move the reusable option to the general settings
   if (!empty($form['reusable'])) {
     $form['reusable']['#type'] = '';
@@ -584,7 +586,7 @@ function panopoly_magic_form_fieldable_panels_panes_fieldable_panels_pane_conten
   }
 }
 
-/** 
+/**
  * Implementation of hook_form_FORM_ID_alter()
  *
  * Provides customizations to the views content type settings form
@@ -593,7 +595,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
 
   // Get the configuration
   $conf = $form_state['conf'];
-  
+
   // Add a widget title setting if views allows this to be customized
   if (!empty($form['override_title'])) {
     $form['override_title_markup']['#access'] = FALSE;
@@ -622,8 +624,8 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     $form['exposed']['link_to_view'] = $form['link_to_view'];
     $form['exposed']['link_to_view']['#parents'] = array('link_to_view');
     unset($form['link_to_view']);
-  } 
-  
+  }
+
   // Add an option to make the more link available if views allows this to happen
   if (!empty($form['more_link'])) {
     $form['more_link']['#id'] = 'more-link';
@@ -632,8 +634,8 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     $form['exposed']['more_link']['#parents'] = array('more_link');
     unset($form['more_link']);
   }
-  
-    
+
+
   // Update the field settings for pagers
   if (!empty($form['use_pager']) && !empty($form['pager_id'])) {
     $form['use_pager']['#prefix'] = '<div class="form-item container-inline">';
@@ -644,7 +646,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     unset($form['use_pager']);
     unset($form['pager_id']);
   }
-  
+
   // Handle the path value that views gives us
   if (!empty($form['path'])) {
     $form['path']['#description'] = t('The URL path used for linking and paging purposes. Leave blank to use the current page.');
@@ -654,7 +656,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     $form['exposed']['path']['#parents'] = array('path');
     unset($form['path']);
   }
-  
+
   // Adjust the items per page and offset settings
   if (!empty($form['items_per_page']) && !empty($form['offset'])) {
     $form['items_per_page']['#field_prefix'] = t('Items to Show');
@@ -688,7 +690,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     $form['display_settings']['offset'] = $form['offset'];
     unset($form['offset']);
   }
-  
+
   // Adjust the sort ordering and sort by options
   if (!empty($form['exposed']['sort_order']) && !empty($form['exposed']['sort_by'])) {
     $form['exposed']['sort_order']['#title'] = t('Sort order');
@@ -809,7 +811,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
       ),
     ),
   );
-   
+
   // Define a general settings fieldset if we have exposed values
   if (!empty($form['exposed']) && count(element_children($form['exposed'])) > 0) {
     $form['exposed']['#type'] = 'fieldset';
@@ -831,7 +833,7 @@ function panopoly_magic_form_views_content_views_panes_content_type_edit_form_al
     $form['content_settings']['#title'] = t('Content Settings');
     $form['content_settings']['#weight'] = -27;
   }
-  
+
   // Define a display settings fieldset if we have display options
   if (!empty($form['display_settings']) && count(element_children($form['display_settings'])) > 0) {
     $form['display_settings']['#type'] = 'fieldset';
@@ -912,13 +914,13 @@ function panopoly_magic_form_ctools_entity_field_content_type_formatter_options_
     $field_name = $form_state['field_instance']['field_name'];
     $field_type = $form_state['field_instance']['widget']['module'];
     $entity = $form_state['entity'];
- 
+
     // Reset the #default_value to the (currently) unsaved entity value.
     if ($field_type == 'image' && !empty($form[$field_name])) {
       $field = $entity->$field_name;
       foreach ($field[LANGUAGE_NONE] as $delta => $value) {
         $form[$field_name][LANGUAGE_NONE][$delta]['#default_value'] = $value;
-      } 
+      }
     }
   }
 
@@ -969,7 +971,7 @@ function panopoly_magic_panelizer_pre_render($element) {
 
 function panopoly_magic_form_ctools_entity_field_content_type_formatter_styles_alter(&$form, &$form_state, $form_id) {
   // Push the panopoly magic submitter onto the front of the submit array.
-  // We need it at the beginning so the entity is saved before the IPE 
+  // We need it at the beginning so the entity is saved before the IPE
   // reloads pane content.
   if (!empty($form_state['entity'])) {
     $form['#submit'][] = 'panopoly_magic_fape_submit';
@@ -991,7 +993,7 @@ function panopoly_magic_fape_submit(&$form, &$form_state) {
   }
 }
 
-/** 
+/**
  * Implementation of hook_form_FORM_ID_alter().
  *
  * Provides customization to panel pane style form
@@ -1085,7 +1087,7 @@ function theme_panopoly_magic_stylizer_preview_form($vars) {
   }
   else {
     $base_types = ctools_get_style_base_types();
- 
+
     if (!empty($base_types[$plugin['module']][$plugin['type']]['preview'])) {
       $preview = $base_types[$plugin['module']][$plugin['type']]['preview'];
     }
@@ -1148,11 +1150,11 @@ function panopoly_magic_views_content_type_modal_submit(&$form, &$form_state) {
 function panopoly_magic_views_pre_view(&$view) {
   if (isset($view->display_handler->options['pane_conf'])) {
     $conf = $view->display_handler->options['pane_conf'];
-  
+
     if (isset($conf['widget_title'])) {
       $view->display_handler->options['defaults']['title'] = FALSE;
-      $view->display_handler->options['title'] = $conf['widget_title']; 
-      $view->build_info['title'] = $conf['widget_title']; 
+      $view->display_handler->options['title'] = $conf['widget_title'];
+      $view->build_info['title'] = $conf['widget_title'];
     }
 
     // Deal with legacy 'nodes' and others (such as 'files') view settings so
@@ -1229,31 +1231,68 @@ function panopoly_magic_preprocess_panels_ipe_toolbar(&$vars) {
 }
 
 /**
+ * Helper function to display the pane for showing previews in the add_content modal
+ */
+function _panopoly_magic_render_preview_pane(&$plugin, $renderer) {
+  $pane = panels_new_pane($plugin['type_name'], $plugin['subtype_name'], TRUE);
+  $display = $renderer->display;
+  $context = $renderer->display->context;
+  $args = $renderer->display->args;
+  $incoming_content = $renderer->display->incoming_content;
+  $keywords = (!empty($renderer->display->keywords)) ? $renderer->display->keywords : array();
+  if ($content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, $keywords, $args, $context, $incoming_content)) {
+    $strip_js = variable_get('panopoly_magic_strip_js_from_preview', 0);
+    $plugin['preview'] = theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
+    if (!empty($strip_js) && !empty($plugin['preview'])) {
+      $plugin['preview'] = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $plugin['preview']);
+    }
+  }
+}
+
+/**
  * Preprocess the panels_add_content_modal() function to add the HTML for the preview
  */
 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_SINGLE) {
+      $query = drupal_get_query_parameters();
+      $type_name = !empty($query['type_name']) ? $query['type_name'] : '';
+      $sub_type = !empty($query['subtype_name']) ? $query['subtype_name'] : '';
+      $plugin = array(
+        'type_name' => $type_name,
+        'subtype_name' => $sub_type,
+      );
+      _panopoly_magic_render_preview_pane($plugin, $vars['renderer']);
+      $vars['column_count'] = 1;
+      $vars['preview_single'] = isset($plugin['preview']) ? $plugin['preview'] : '';
+      $vars['preview_single_title'] = '';
+      foreach ($vars['categories'][$vars['category']]['content'] as $key => $plugin) {
+        if ($plugin['subtype_name'] == $sub_type) {
+          $vars['preview_single_title'] = $key;
+          break;
+        }
+      }
+    }
     foreach ($vars['categories'][$vars['category']]['content'] as &$plugin) {
-      $use_preview = (variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT) == PANOPOLY_ADD_PREVIEW_AUTOMATIC);
-      $strip_js = variable_get('panopoly_magic_strip_js_from_preview', 0);
       $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 (!empty($use_preview) || in_array($plugin['subtype_name'], $preview_panes)) {
-        $pane = panels_new_pane($plugin['type_name'], $plugin['subtype_name'], TRUE);
-        $display = $vars['renderer']->display;
-        $context = $vars['renderer']->display->context;
-        $args = $vars['renderer']->display->args;
-        $incoming_content = $vars['renderer']->display->incoming_content;
-        $keywords = (!empty($vars['renderer']->display->keywords)) ? $vars['renderer']->display->keywords : array();
-        if ($content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, $keywords, $args, $context, $incoming_content)) {
-          $plugin['preview'] = theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
-          if (!empty($strip_js) && !empty($plugin['preview'])) {
-            $plugin['preview'] = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $plugin['preview']);
-          }
-        }
+      if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
+        // Convert the link to generate a preview of itself.
+        $options = array(
+          'query' => array(
+            'type_name' => $plugin['type_name'],
+            'subtype_name' => $plugin['subtype_name'],
+          ),
+          'attributes' => array('class' => array('use-ajax button'))
+        );
+        $plugin['title'] = l($plugin['title'], current_path(), $options);
+      }
+      elseif ($use_preview == PANOPOLY_ADD_PREVIEW_AUTOMATIC || in_array($plugin['subtype_name'], $preview_panes)) {
+        _panopoly_magic_render_preview_pane($plugin, $vars['renderer']);
       }
       else {
 
@@ -1269,11 +1308,12 @@ function panopoly_magic_preprocess_panels_add_content_modal(&$vars) {
   }
 }
 
-/** 
+/**
  * Process the panels_add_content_modal() to adjust the markup to present the preview
  */
 function panopoly_magic_process_panels_add_content_modal(&$vars) {
-  if (variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT) == PANOPOLY_ADD_PREVIEW_DISABLED) {
+  $use_preview = variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT);
+  if ($use_preview == PANOPOLY_ADD_PREVIEW_DISABLED) {
     return;
   }
 
@@ -1296,6 +1336,25 @@ function panopoly_magic_process_panels_add_content_modal(&$vars) {
       $vars['columns'][$which] = '';
     }
 
+    if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
+      $title = $vars['preview_single_title'];
+      $legend_title = isset($content[$title]) ? $content[$title]['title'] : '';
+      $content[$title]['title'] = 'Add';
+      $vars['columns'][0] = '';
+      $vars['columns'][0] .=
+        '<fieldset class="widget-preview"><legend><div class="widget-preview-title">' .
+        (!empty($vars['preview_single']) ?
+          theme('panels_add_content_link', array(
+            'renderer' => $vars['renderer'],
+            'region' => $vars['region'],
+            'content_type' => $content[$title]
+          )) : '') .
+        '</div><span class="fieldset-legend">' . $vars['preview_single_title'] . '</span></legend><div class="fieldset-wrapper">' .
+        (!empty($vars['preview_single']) ? $vars['preview_single'] : t('No Preview.  Select a pane to show its preview.')) .
+        '</div></fieldset>';
+      $content[$title]['title'] = $legend_title;
+    }
+
     // Read the column data with our preview functionality
     $count = 0;
     foreach ($titles as $title) {
@@ -1305,8 +1364,31 @@ function panopoly_magic_process_panels_add_content_modal(&$vars) {
       if (empty($content[$title]['description'])) {
         $content[$title]['description'] = $title;
       }
+      $legend_title = $content[$title]['title'];
       $content[$title]['title'] = 'Add';
-      $vars['columns'][$which] .= '<fieldset class="widget-preview"><legend><div class="widget-preview-title">' . theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content[$title])) . '</div><span class="fieldset-legend">' . $title . '</span></legend><div class="fieldset-wrapper">' . (!empty($content[$title]['preview']) ? $content[$title]['preview'] : t('No Preview')) . '</div></fieldset>';
+      if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
+        $vars['columns'][$which] .=
+          '<div class="content-wrapper">' .
+          theme('panels_add_content_link', array(
+            'renderer' => $vars['renderer'],
+            'region' => $vars['region'],
+            'content_type' => $content[$title]
+          )) .
+          '<span class="fieldset-legend">' . $legend_title . '</span>' .
+          '</div>';
+      }
+      else {
+        $vars['columns'][$which] .=
+          '<fieldset class="widget-preview"><legend><div class="widget-preview-title">' .
+          theme('panels_add_content_link', array(
+            'renderer' => $vars['renderer'],
+            'region' => $vars['region'],
+            'content_type' => $content[$title]
+          )) .
+          '</div><span class="fieldset-legend">' . $legend_title . '</span></legend><div class="fieldset-wrapper">' .
+          (!empty($content[$title]['preview']) ? $content[$title]['preview'] : t('No Preview')) .
+          '</div></fieldset>';
+      }
     }
   }
 }
@@ -1364,4 +1446,3 @@ function panopoly_magic_view_mode_options($entity_type = 'node') {
   }
   return $options;
 }
-
-- 
1.9.3 (Apple Git-50)

