diff --git a/panopoly_magic.module b/panopoly_magic.module index ab008f3..cfe5530 100644 --- a/panopoly_magic.module +++ b/panopoly_magic.module @@ -7,15 +7,6 @@ define('PANOPOLY_ADD_PREVIEW_DISABLED', 2); define('PANOPOLY_ADD_PREVIEW_DEFAULT', PANOPOLY_ADD_PREVIEW_AUTOMATIC); /** - * Implements hook_ctools_plugin_directory() - */ -function panopoly_magic_ctools_plugin_directory($owner, $plugin_type) { - if ($owner == 'ctools' && $plugin_type == 'content_types') { - return 'plugins/' . $plugin_type; - } -} - -/** * Implements hook_init() */ function panopoly_magic_init() { @@ -259,6 +250,24 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) { // 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. + $default_values = array( + 'language' => '', + 'title' => '', + 'link' => '', + 'path' => '', + 'reusable' => '', + 'category' => '', + 'admin_title' => '', + 'admin_description' => '', + 'revision' => '', + ); + + if (!empty($form_state['values'])) { + $form_state['values'] = array_merge($default_values, $form_state['values']); + } + else { + $form_state['values'] = $default_values; + } // // This code is copied from fieldable_panels_panes_entity_edit_form_submit(): @@ -289,8 +298,8 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) { // End code copied from fieldable_panels_panes_entity_edit_form_submit(). // - // Define the content type plugin to use for rendering the preview. - $preview_type = 'fieldable_panels_pane_preview'; + // Set the callback to use for rendering the preview. + $preview_callback = 'panopoly_magic_render_fieldable_panels_pane_preview'; // Stash the entity stub for the preview content type. $pane->configuration['fieldable_panels_pane'] = $entity; @@ -341,7 +350,7 @@ function panopoly_magic_form_alter(&$form, &$form_state, $form_id) { // inside form and double rendering. $form['#post_render'][] = 'panopoly_magic_form_post_render_preview'; $form['#panopoly_magic_preview_info'] = array( - 'preview_type' => isset($preview_type) ? $preview_type : NULL, + 'preview_callback' => isset($preview_callback) ? $preview_callback : NULL, 'pane' => $pane, 'configuration' => $configuration, 'keywords' => $keywords, @@ -482,14 +491,10 @@ 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_type)) { - $content = ctools_content_render($pane->type, $pane->subtype, $configuration, $keywords, $args, $context); + if (empty($preview_callback)) { + $preview_callback = 'ctools_content_render'; } - // If a preview type was specified, use that to render the preview. - else { - $content = ctools_content_render($preview_type, $pane->subtype, $configuration, $keywords, $args, $context); - } - + $content = $preview_callback($pane->type, $pane->subtype, $configuration, $keywords, $args, $context); // Create the fieldset with appropriate content $preview = array( @@ -512,6 +517,33 @@ function panopoly_magic_form_post_render_preview($output, $form) { } /** + * Renders previews for fieldable_panels_pane content types. + */ +function panopoly_magic_render_fieldable_panels_pane_preview($type, $subtype, $conf, $keywords, $args, $context) { + $entity = $conf['fieldable_panels_pane']; + if ($entity && fieldable_panels_panes_access('view', $entity)) { + $settings = field_bundle_settings('fieldable_panels_pane', $entity->bundle); + $block = new stdClass(); + $block->title = ''; + if (empty($settings['extra_fields']['display']) || !empty($settings['extra_fields']['display']['title']['default']['visible'])) { + if (!empty($entity->title)) { + if ($entity->link) { + $block->title = l($entity->title, $entity->path); + } + else { + $block->title = check_plain($entity->title); + } + } + } + + $view_mode = isset($conf['view_mode']) ? $conf['view_mode'] : 'full'; + $block->content = fieldable_panels_panes_view($entity, $view_mode); + + return $block; + } +} + +/** * Recursively parse form elements to add special autosubmit handling on a per field-type basis. */ function panopoly_magic_autosubmit_configure(&$element) { diff --git a/plugins/content_types/fieldable_panels_pane_preview.inc b/plugins/content_types/fieldable_panels_pane_preview.inc deleted file mode 100644 index a6e8ac5..0000000 --- a/plugins/content_types/fieldable_panels_pane_preview.inc +++ /dev/null @@ -1,43 +0,0 @@ - t('Fielded custom content (preview)'), - 'no title override' => TRUE, - 'description' => t('Preview for created custom panels pane with fields'), - 'category' => t('Fielded panes'), - 'all contexts' => TRUE, - 'defaults' => array( - 'view_mode' => 'full', - ), -); - -/** - * Callback to render our content type preview. - * - * Render FPP based on entity stashed in configuration for the preview. - * - * @see fieldable_panels_panes_fieldable_panels_pane_content_type_render(). - */ -function panopoly_magic_fieldable_panels_pane_preview_content_type_render($subtype, $conf, $panel_args = array(), $context = array()) { - $entity = $conf['fieldable_panels_pane']; - $view_mode = isset($conf['view_mode']) ? $conf['view_mode'] : 'full'; - if ($entity && fieldable_panels_panes_access('view', $entity)) { - $settings = field_bundle_settings('fieldable_panels_pane', $entity->bundle); - $block = new stdClass(); - $block->title = ''; - if (empty($settings['extra_fields']['display']) || !empty($settings['extra_fields']['display']['title']['default']['visible'])) { - $block->title = !empty($entity->title) ? filter_xss_admin($entity->title) : ''; - } - $block->content = fieldable_panels_panes_view($entity, $view_mode); - return $block; - } -}