Almost there.
[EDIT - removed a blow-by-blow debugging session]
... I figured it out!
Here's the missing manual, or at least missing example.
The mini-tute in http://drupal.org/node/218960#comment-811545 was pretty much the process I could figure out from the code.
BUT
that involves putting my stuff in the module folder. Looking at both the code and the API docs there seems to be an extremely robust plugin loader available...
but huh? it's not doing drupal hooks like normal.
Eventually I traced the plugin loader and related funcs : HOOK_panels_include_directory() enough to get it all into a contrib. Here's a delibrately simple custom renderer. Use it as a package to build on to make your own selectable styles..
Note this is deliberately not as clever as the distro ones - but is maybe a bit more hands-on and obvious.
For easy reference, I'll paste it in here directly:
boxer.module
/**
* @file
*
* This is a DEMONSTRATION file to assist learning how to make your own panel
* styles. It doesn't add a lot of functionality, in fact it took 'rounded
* corners and removed most of the magic. But it DOES show the hook names - and
* more importantly the bits that needed to be added to your own panels plugin
* module.
*
* This utility basically only adds a 'style' selector to your panels admin,
* which adds a css class to the element. BUT from this code you now have full
* access to all the HTML and CSS relevant.
*
* This example only does render_panel (not render_pane) but you can copy the
* bits from panels/styles/block.inc if you want.
*
* Take it from there.
*
* @author dman coders.co.nz
*/
/**
* Include a theme tweak for panels
*
* Panels does a lot of magic loading, it does NOT use normal
* module_implements() to load its hooks, so we have to do this:
*
* @see HOOK_panels_include_directory()
* @see http://doxy.samboyer.org/panels2/group__HookInvokers.html
*/
function boxer_panels_include_directory($plugintype) {
if($plugintype == 'styles') {
return 'panels_inc/' .$plugintype;
}
}
/**
* NEED to declare the theme names and the include files.
*
* Or nothing works! Remember to flush the cache when you change this.
*
* @see HOOK_theme()
*/
function boxer_theme() {
$theme = array();
$theme['boxer_boxed_corners_style_render_panel'] = array(
'arguments' => array('content' => NULL, 'pane' => NULL, 'display' => NULL),
'path' => 'panels_inc/styles/boxed_corners.inc',
);
return $theme;
}
boxer/panels_inc/styles/boxed_corners.inc
// $Id: $
/**
* @file styles/boxed_corners.inc
* Definition of the 'boxed_corners' panel style.
*
* Based on rounded_corner.inc from panels.module
*
* BUT MUCH DUMBED DOWN so you can see the important bits, not the clever bits.
*
* @author dman coders.co.nz
*/
// ---------------------------------------------------------------------------
// Panels hooks.
/**
* Implementation of HOOK_STYLENAME_panels_styles().
*
* Where HOOK is the modulename as normal, and STYLENAME matches this inc
* filename.
*/
function boxer_boxed_corners_panels_styles() {
return array(
'boxed_corners' => array(
'title' => t('Boxed corners'),
'description' => t('Presents the panes or panels with a folded corner box around them'),
'render panel' => 'boxer_boxed_corners_style_render_panel',
'settings form' => 'boxer_boxed_corners_style_settings_form',
),
);
}
// ---------------------------------------------------------------------------
// Panels style plugin callbacks.
/**
* Render callback.
*
* Declared by name in the HOOK_panels_style() above.
*
* @ingroup themeable
*/
function theme_boxer_boxed_corners_style_render_panel($display, $panel_id, $panes, $settings) {
$output = '';
foreach ($panes as $pane_id => $pane) {
$text = panels_render_pane($pane, $display->content[$pane_id], $display);
if ($text) {
$output .= boxer_boxed_corners_box($text);
}
}
boxer_add_boxed_corners_css($display);
return $output;
}
/**
* Generates the CSS and adds it to the current page head.
*
* Note this does NOT do anything that cannot already be done with CSS! It's
* here to show what COULD be done if you wanted to mess around.
*
* For something this trivial, you may as well add a normal css file BUT you can
* also do contextual or code things by writing it dynamically.
*
* @param $display
* A Panels display object.
*/
function boxer_add_boxed_corners_css($display) {
static $displays_used = array();
if (empty($displays_used[$display->css_id])) {
$idstr = empty($display->css_id) ? '.boxed-corner' : "#$display->css_id";
$url = url( drupal_get_path('module', 'boxer') . '/images', array('absolute' => TRUE));
#######################################
$css = <<<EOF
$idstr {
padding-bottom:6px;
}
$idstr .boxed-corner-inner {
border-left:1px solid #DDDDDD;
border-top:1px solid #DDDDDD;
background:transparent url($url/block-right-bottom-bg.gif) no-repeat scroll right bottom;
overflow:hidden;
padding:5px 5px 10px;
}
EOF;
#######################################
drupal_set_html_head("<style type=\"text/css\" media=\"all\">\n$css</style>\n");
$displays_used[$display->css_id] = TRUE;
}
}
/**
* Settings form callback.
*
* Example stub function only
*
* See the panels.module distribution for panels with extra settings.
*
*/
function boxer_boxed_corners_style_settings_form($style_settings) {
$form['info'] = array(
'#type' => 'markup',
'#value' => t('No settings'),
);
return $form;
}
/**
* Create the HTML for our boxed corner box.
*
* This doesn't add much to the normal rendering. But you can mess with it now.
*
* @param $text
* The content of this rounded corner box.
*
* @return
* The created HTML.
*/
function boxer_boxed_corners_box($content) {
#######################################
return <<<EOF
<div class="boxed-corner">
<div class="boxed-corner-top"></div>
<div class="boxed-corner-inner">
$content
</div>
<div class="boxed-corner-bottom"></div>
</div>
EOF;
#######################################
}
Comment | File | Size | Author |
---|---|---|---|
#14 | panels_plugin_example.tgz | 7.25 KB | rfay |
boxer-demo_panels_style.tar_.gz | 11.48 KB | dman |
Comments
Comment #1
MichelleThis looks very helpful. I've never tried making my own style and it's nice to have a simple example to work from.
Thanks,
Michelle
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedThis needs to be updated for the ctools integration for this to be useful.
Comment #3
mclin CreditAttribution: mclin commentedNo matter what I do, I can't seem to get my style to show up in 'Pane style for "x"' dialog...
I even tried copying panels/plugins/styles/default.inc to default2.inc and putting a 2 after everything and still nothing show up.
I wonder if this has anything to do with this ctools integration you speak of.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedYou must implement hook_ctools_plugin_directories() so that CTools knows what directories to search. That would be the first thing to check.
Comment #5
H3x CreditAttribution: H3x commentedSorry to be a nag, but how exactly would one implement hook_ctools_plugin_directories()? I apologize for my low-level php knowledge, but this feature would really add a lot of functionality to Panels.
Comment #6
mclin CreditAttribution: mclin commentedFor just copying default.inc to get a new style, I discovered that while the new style wasn't showing up in the pane style dialog, it was showing up in region style. Good enough for me! Thanks for the reply.
Comment #7
CarbonPig CreditAttribution: CarbonPig commentedsubscribe
Comment #8
rfaySubscribing
Comment #9
webthingee CreditAttribution: webthingee commentedSubscribing
Comment #10
webthingee CreditAttribution: webthingee commentedA Themer's Solution....
I have in my theme a directory called plugins.
in there I have layouts and styles
in styles I have a folder called thintop
and... in there I have 2 files (tho I have commented out the template file in favor of this fancy rendering which gives me admin links and extra stuff in my pane...
thintop.inc and THEME-NAME-thintop.tpl.php
(based on http://drupal.org/node/495654)
The .inc looks like this
when I was using a template the $output was
and the tpl.php is pretty basic
IMPORTANT!!!
Add to your .info file in your theme!!
remember to clear the theme registry
Comment #11
rfayPutting this on the priority list for November. @webthingee or I will try to make it happen.
Comment #12
perhenrik CreditAttribution: perhenrik commentedSubscribe (and yes, im looking for a good howto or bp on how to add styles...)
Comment #13
amcc CreditAttribution: amcc commentedIf you want to add a style in your theme rather than as a module I've written a tutorial here:
http://01am.co.uk/blog/creating-style-plugins-panels-your-theme-folder
let me know if you need more info
Comment #14
rfayAttached is a "panels plugin example" module intended to be placed in a subdirectory of the panels project. Better yet, it could go into panels/examples/panels_plugin_example. I imagine we'll have other modules in there someday.
This example shows how to use style and layout plugins, explains the path and filenaming conventions, and provides advanced help.
Let me know how you like it.
Thanks very much for the excellent references from #13:
Creating a Panels style plugin
and
Creating a Panels plugin in the theming layer.
Thanks,
-Randy
Comment #15
rfayTwo new resources:
http://activelamp.com/blog/advanced-drupal-theming-using-panels-part-1-e...
http://www.chapterthree.com/blog/farsheed_hamiditoosi/my_life_panels_vol_1
Comment #16
montesde CreditAttribution: montesde commentedHow would you use this to theme a form when using panels to override an add/edit page? I can get the plugin to work but i'm not exactly sure how to get it to understand the $form variables. I'm trying to use a tpl.php file. I think it has to do with my output function in my .inc file.
Anyone have any insight?
Comment #17
cap60552 CreditAttribution: cap60552 commentedIs there a separate callback for a settings form for an individual pane?
'settings form' seem to only be triggered when the default, or individual region settings are diplayed, but not individual panes setting.
I would like to be able to present a form field, or radio buttons (haven't yet decided) to allow the designer to specify an icon that would appear next to the title of the pane. So far I have only been able to get this to appear in all panes in a region instead of a single individual pane.
Any ideas?
Comment #18
merlinofchaos CreditAttribution: merlinofchaos commented'pane settings form'
Comment #19
cap60552 CreditAttribution: cap60552 commentedThanks merlin, that was exactly what i was looking for!
Comment #20
bachbach CreditAttribution: bachbach commentedthanks for this tuto,
does anyone can help me on adding the skinr form to a custom plugin style pane settings ?
Comment #21
bachbach CreditAttribution: bachbach commentedoups sorry i changed the tags
Comment #22
DamienMcKennaComment #23
vijaycs85As far as I understand the issue summary, this issue is trying to add an example module to explain something in panels module? If so, please move this issue toExamples Module.