From 2216cad0490214eb03e050feb0fa10edc0ce8f41 Mon Sep 17 00:00:00 2001 From: Helior Colorado Date: Tue, 22 May 2012 15:50:21 -0700 Subject: [PATCH 1/2] Introducing Display wrapper styles. --- panels.module | 7 +++ .../panels_renderer_editor.class.php | 53 ++++++++++++++++++-- .../panels_renderer_standard.class.php | 40 ++++++++++++++- plugins/styles/default.inc | 9 +++ 4 files changed, 102 insertions(+), 7 deletions(-) diff --git a/panels.module b/panels.module index bab42b2..362fe30 100644 --- a/panels.module +++ b/panels.module @@ -136,6 +136,13 @@ function panels_theme() { 'file' => $data['file'], ); } + if (!empty($data['render display'])) { + $theme[$data['render display']] = array( + 'variables' => array('content' => NULL, 'display' => NULL, 'style' => NULL, 'settings' => NULL), + 'path' => $data['path'], + 'file' => $data['file'], + ); + } if (!empty($data['hook theme'])) { if (is_array($data['hook theme'])) { diff --git a/plugins/display_renderers/panels_renderer_editor.class.php b/plugins/display_renderers/panels_renderer_editor.class.php index 7aa9700..b18cb8d 100644 --- a/plugins/display_renderers/panels_renderer_editor.class.php +++ b/plugins/display_renderers/panels_renderer_editor.class.php @@ -177,7 +177,7 @@ class panels_renderer_editor extends panels_renderer_standard { /** * Get the style links. * - * This is abstracted out since we have styles on both panes and regions. + * This is abstracted out since we have styles on panes, regions, and displays. */ function get_style_links($type, $id = NULL) { $info = $this->get_style($type, $id); @@ -197,7 +197,7 @@ class panels_renderer_editor extends panels_renderer_standard { 'attributes' => array('class' => array('ctools-use-modal')), ); - $function = $type != 'pane' ? 'settings form' : 'pane settings form'; + $function = $type == 'region' ? 'settings form' : "$type settings form"; if (panels_plugin_get_function('styles', $style, $function)) { $style_links[] = array( 'title' => t('Settings'), @@ -218,6 +218,18 @@ class panels_renderer_editor extends panels_renderer_standard { $links = array(); if (user_access('administer panels styles')) { + $wrapper_style_links = $this->get_style_links('display_wrapper'); + $links[] = array( + 'title' => '' . t('Wrapper Style') . '' . theme_links(array('links' => $wrapper_style_links, 'attributes' => array(), 'heading' => array())), + 'html' => TRUE, + 'attributes' => array('class' => array('panels-sub-menu')), + ); + + $links[] = array( + 'title' => '
', + 'html' => TRUE, + ); + $style_links = $this->get_style_links('display'); $links[] = array( 'title' => '' . t('Style') . '' . theme_links(array('links' => $style_links, 'attributes' => array(), 'heading' => array())), @@ -928,6 +940,11 @@ class panels_renderer_editor extends panels_renderer_standard { // This lets us choose whether we're doing the display's cache or // a pane's. switch ($type) { + case 'display_wrapper': + $style = isset($this->display->panel_settings['display_wrapper']['style']) ? $this->display->panel_settings['display_wrapper']['style'] : 'default'; + $title = t('Panel style for display'); + break; + case 'display': $style = isset($this->display->panel_settings['style']) ? $this->display->panel_settings['style'] : 'default'; $title = t('Default style for this display'); @@ -977,7 +994,7 @@ class panels_renderer_editor extends panels_renderer_standard { // Preserve this; this way we don't actually change the method until they // have saved the form. $style = panels_get_style($form_state['style']); - $function = panels_plugin_get_function('styles', $style, ($type == 'pane') ? 'pane settings form' : 'settings form'); + $function = panels_plugin_get_function('styles', $style, ($type == 'region') ? 'settings form' : "$type settings form"); if (!$function) { if (isset($this->cache->style)) { unset($this->cache->style); @@ -985,6 +1002,13 @@ class panels_renderer_editor extends panels_renderer_standard { // If there's no settings form, just change the style and exit. switch($type) { + case 'display_wrapper': + $this->display->panel_settings['display_wrapper']['style'] = $form_state['style']; + if (isset($this->display->panel_settings['display_wrapper']['settings'])) { + unset($this->display->panel_settings['display_wrapper']['settings']); + } + break; + case 'display': $this->display->panel_settings['style'] = $form_state['style']; if (isset($this->display->panel_settings['style_settings']['default'])) { @@ -1045,6 +1069,11 @@ class panels_renderer_editor extends panels_renderer_standard { $defaults = isset($style['defaults']) ? $style['defaults'] : array(); // Get the &$conf variable based upon whose style we're editing. switch ($type) { + case 'display_wrapper': + $this->display->panel_settings['display_wrapper']['style'] = $this->cache->style; + $this->display->panel_settings['display_wrapper']['settings'] = $default; + break; + case 'display': $this->display->panel_settings['style'] = $this->cache->style; $this->display->panel_settings['style_settings']['default'] = $defaults; @@ -1065,6 +1094,10 @@ class panels_renderer_editor extends panels_renderer_standard { } else { switch ($type) { + case 'display_wrapper': + $style = panels_get_style((!empty($this->display->panel_settings['display_wrapper']['style'])) ? $this->display->panel_settings['display_wrapper']['style'] : 'default'); + break; + case 'display': $style = panels_get_style((!empty($this->display->panel_settings['style'])) ? $this->display->panel_settings['style'] : 'default'); break; @@ -1082,6 +1115,10 @@ class panels_renderer_editor extends panels_renderer_standard { // Set up our $conf reference. switch ($type) { + case 'display_wrapper': + $conf = &$this->display->panels_settings['display_wrapper']; + break; + case 'display': $conf = &$this->display->panel_settings['style_settings']['default']; break; @@ -1615,12 +1652,20 @@ function panels_edit_style_type_form($form, &$form_state) { $styles = panels_get_styles(); - $function = ($type == 'pane' ? 'render pane' : 'render region'); $options = array(); if ($type == 'region') { $options[-1] = t('Use display default style'); } + if ($type == 'display') { + $type = 'region'; + } + else if ($type == 'display_wrapper') { + $type = 'display'; + } + + $function = ("render $type"); + uasort($styles, 'ctools_plugin_sort'); foreach ($styles as $id => $info) { diff --git a/plugins/display_renderers/panels_renderer_standard.class.php b/plugins/display_renderers/panels_renderer_standard.class.php index bddf744..7b8f805 100644 --- a/plugins/display_renderers/panels_renderer_standard.class.php +++ b/plugins/display_renderers/panels_renderer_standard.class.php @@ -194,6 +194,7 @@ class panels_renderer_standard { function prepare($external_settings = NULL) { $this->prepare_panes($this->display->content); $this->prepare_regions($this->display->panels, $this->display->panel_settings); + $this->prepare_display_wrapper($this->display->panel_settings); $this->prep_run = TRUE; } @@ -266,7 +267,7 @@ class panels_renderer_standard { * and continue. * - If the region has no explicit style, but a style was set at the display * level, then inherit the style from the display. - * - If neither the region nor the dispay have explicitly set styles, then + * - If neither the region nor the display have explicitly set styles, then * fall back to the hardcoded 'default' style, a very minimal style. * * The other important task accomplished by this method is ensuring that even @@ -327,6 +328,18 @@ class panels_renderer_standard { } /** + * Prepare the display wrapper. + */ + function prepare_display_wrapper($settings) { + $defaults = array( + 'style' => isset($settings['display_wrapper']['style']) ? $settings['display_wrapper']['style'] : 'default', + 'settings' => isset($settings['display_wrapper']['settings']) ? $settings['display_wrapper']['settings'] : array(), + ); + + $this->prepared['display_wrapper'] = $defaults; + } + + /** * Build inner content, then hand off to layout-specified theme function for * final render step. * @@ -345,19 +358,40 @@ class panels_renderer_standard { $this->add_meta(); if (empty($this->display->cache['method']) || !empty($this->display->skip_cache)) { - return $this->render_layout(); + return $this->render_display_wrapper(); } else { $cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context); if ($cache === FALSE) { $cache = new panels_cache_object(); - $cache->set_content($this->render_layout()); + $cache->set_content($this->render_display_wrapper()); panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context); } return $cache->content; } } + function render_display_wrapper() { + $content = $this->render_layout(); + + if (!empty($content)) { + $display_style = $this->prepared['display_wrapper']['style']; + $display_settings = $this->prepared['display_wrapper']['settings']; + $style = panels_get_style($display_style); + + if (isset($style) && isset($style['render display'])) { + $output = theme($style['render display'], array('content' => $content, 'display' => $this->display, 'style' => $style, 'settings' => $display_settings)); + + // This could be null if no theme function existed. + if (isset($output)) { + return $output; + } + } + } + + return $content; + } + /** * Perform display/layout-level render operations. * diff --git a/plugins/styles/default.inc b/plugins/styles/default.inc index 9e89cbc..0008038 100644 --- a/plugins/styles/default.inc +++ b/plugins/styles/default.inc @@ -10,6 +10,7 @@ $plugin = array( 'title' => t('No style'), 'description' => t('The default panel rendering style; displays each pane with a separator.'), 'render region' => 'panels_default_style_render_region', + 'render display' => 'panels_default_style_render_display', ); /** @@ -25,3 +26,11 @@ function theme_panels_default_style_render_region($vars) { return $output; } +/** + * Render callback + * + * @ingroup themable + */ +function theme_panels_default_style_render_display($vars) { + return $vars['content']; +} \ No newline at end of file -- 1.7.6 From cb3095215831001122bb8e86df3490e098282d09 Mon Sep 17 00:00:00 2001 From: Helior Colorado Date: Tue, 22 May 2012 16:26:59 -0700 Subject: [PATCH 2/2] Fixed bug with display style settings link; Added rounded corner 'render display' --- .../panels_renderer_editor.class.php | 3 ++- plugins/styles/corners/rounded_corners.inc | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/plugins/display_renderers/panels_renderer_editor.class.php b/plugins/display_renderers/panels_renderer_editor.class.php index b18cb8d..a1339d0 100644 --- a/plugins/display_renderers/panels_renderer_editor.class.php +++ b/plugins/display_renderers/panels_renderer_editor.class.php @@ -197,7 +197,8 @@ class panels_renderer_editor extends panels_renderer_standard { 'attributes' => array('class' => array('ctools-use-modal')), ); - $function = $type == 'region' ? 'settings form' : "$type settings form"; + $function = ($type == 'display' || $type == 'region') ? 'settings form' : "$type settings form"; + if (panels_plugin_get_function('styles', $style, $function)) { $style_links[] = array( 'title' => t('Settings'), diff --git a/plugins/styles/corners/rounded_corners.inc b/plugins/styles/corners/rounded_corners.inc index a1d800b..4b1d718 100644 --- a/plugins/styles/corners/rounded_corners.inc +++ b/plugins/styles/corners/rounded_corners.inc @@ -11,6 +11,7 @@ $plugin = array( 'description' => t('Presents the panes or panels with a rounded corner box around them'), 'render region' => 'panels_rounded_corners_style_render_region', 'render pane' => 'panels_rounded_corners_style_render_pane', + 'render display' => 'panels_rounded_corners_style_render_display', 'settings form' => 'panels_rounded_corners_style_settings_form', 'hook theme' => array( 'panels_rounded_corners_box' => array( @@ -92,6 +93,22 @@ function theme_panels_rounded_corners_style_render_pane($vars) { } /** + * Render callback for the entire display. + */ +function theme_panels_rounded_corners_style_render_display($vars) { + $content = $vars['content']; + $display = $vars['display']; + + if (empty($content)) { + return; + } + + $output = theme('panels_rounded_corners_box', array('content' => $content)); + panels_add_rounded_corners_css($display, NULL); + return $output; +} + +/** * Settings form callback. */ function panels_rounded_corners_style_settings_form($style_settings) { -- 1.7.6