Skip to Content
RSSGrab the RSS feed! ->

How to create a panels style plugin

Creating panels styles can be very powerful. You can define certain styles for your client to choose from, so they can choose what type of display the panel pane will be like. This way you keep the workflow clean, your code under revision control, your themer gets to keep his sanity, and your concious stays clear.

This article assumes you know about running panels, and more or less what the nomenclature is. You should know also that panels now uses ctools, which is is primarily a set of APIs and tools to improve the developer experience.

So, what we'll be doing here is actually creating a ctools plugin, to implement a new panels style. Sorry if I'm confusing you already, don't worry, it's actually quite straight forward, we want to be able to do this:

choose_style.png
... and then this:
choose_style2.png

OK, now to the meat of it. We'll call our module ctoolsplugins.

1. Create a new module, and tell ctools about our plugins

What you need is very basic, an info file and a module file. So far, nothing new.

1.1 Declare our dependencies

So we obviously need ctools module on our site, and well, the plugin wouldn't make much sense without panels and page_manager, so:

; $Id:
name = Ctools Plugins
description = Our custom ctools plugins
core = 6.x
dependencies[] = ctools
dependencies[] = panels
dependencies[] = page_manager
package = Chaos tool suite

1.2 Implement hook_ctools_plugin_directory to tell ctools about our plugins

In our module file, of course, we'll implement this function, that will check if ctools if looking for style plugins, and lets if so, it will let it know where ours are:

<?php
/**
  * Implementation of hook_ctools_plugin_directory().
  */
function ctoolsplugins_ctools_plugin_directory($module, $plugin) {
  if (
$module == 'panels' && $plugin == 'styles') {
    return
'plugins/' . $plugin;
  }
}
?>

2. Prepare our file structure for the plugins, and create our plugin file.

This image is pretty self explanatory:

ctoolsplugin_directories.png
We'll call our plugin 'collapsible', so we create inside ctoolsplugins/plugins/styles/ a file called collapsible.inc.

3. Implement our style plugin in collapsible.inc

3.1 Define your style goals and necessities.

OK, Here you should think about what you are going to do with the plugin.

  • Is it just for markup?
  • Will you be offering different options?
  • Will you be implementing javascript on it?

In our case, we'll take the opportunity, to teach you another thing that ctools has, the collapsible div utility. So our style will basically convert any panels pane, into a collapsible panels pane:
collapsed_pane.png

And because we are friendly developers (or like not to be ever bothered after developing it), we'll give the user a chance to configure if they want the pane to start opened or closed. That means an extra settings form, so we can have this:
ctools_style_options.png

3.2 Imlement hook_panels_style_info

The naming is very important here, it should be modulename_stylename_panels_style. You basically return an array, defining your style:

<?php
/**
* @file
* Definition of the 'collapsible' panel style.
*/


/**
* Implementation of hook_panels_style_info().
*/
function ctoolsplugins_collapsible_panels_styles() {
  return array(
     
'title' => t('Collapsible div'),
     
'description' => t('Display the pane in a collapsible div.'),
     
'render pane' => 'ctoolsplugins_collapsible_style_render_pane',
     
'pane settings form' => 'ctoolsplugins_collapsible_style_settings_form',
  );
}
?>

'title' and 'description' are pretty self explanatory.
'render pane' specifies the theme function we'll be providing for rendering the pane. Watch the naming convention.
'pane settings form' specifies the callback function which provides the extra settings form, that we'll be using for our start up options. Watch the naming convention.

3.3 Define the settings form callback.

The name of the function will be what you specified in 'pane settings form' earlier. Just provide a new array inside $form, for each configuration you want the user to specify. See the FAPI documentation for reference.

<?php
/**
* Settings form callback.
*/
function ctoolsplugins_collapsible_style_settings_form($style_settings) {
 
$form['collapsed'] = array(
   
'#type' => 'select',
   
'#title' => t('Startup behaviour'),
   
'#options' => array(
     
0 => t('Start opened'),
     
1 => t('Start collapsed'),
    ),
   
'#default_value' => (isset($style_settings['collapsed'])) ? $style_settings['collapsed'] : 'opened',
   
'#description' => t('Choose whether you want the pane to start collapsed or opened'),
  );

  return
$form;
}
?>

This is pretty straight forward, in our case we provide two options, one to start opened and one to start collapsed. If collapsed is chosen, the value will be 1.

3.4 Define the render callback function.

The name of the function will be what you previously specified in 'render pane'. This is just a theme function, and where you have the chance of altering what will be shown to the user when viewing the page.

<?php
/**
* Render callback.
*
* @ingroup themeable
*/
function theme_ctoolsplugins_collapsible_style_render_pane($content, $pane, $display) {
 
$style_settings = $pane->style['settings']; // good idea for readability of code if you have a ton of settings
 
$start_settings = $style_settings['collapsed']; // we can do this be cause the only values possible are 0 or 1

 
$pane_content = $content->content;

  if (
$content->title) {
   
$pane_title = '<h2 class="pane-title">'. $content->title .'</h2>';

   
// theme('ctools_collapsible', $handle, $content, $collapsed);
   
$result = theme('ctools_collapsible', $pane_title, $pane_content, $start_settings);
  }

 
// if we don't have a pane title, we just print out the content as normaly, since there's no handle
 
else {
   
$result = $pane_content;
  }

  return
$result;
}
?>

Important to note here, is that our user's specified settings are inside $pane->style['settings']. In this example we check if there's a title available, and if so we implement the ctools_collapsible theme function to get our collapsible panes. Other wise we don't have a handle, and we just return the content as normal.

And that is it. Hope you found the article useful, and if you'd like me to write up some more articles about writing plugins for panels/ctools, drop a comment with your question/suggestion!

UPDATE:You can also provide a style plugin in your theme, as shown in this fine tutorial.

AttachmentSize
ctoolsplugins.tar.gz1.3 KB

184 responses to this article.

#1

Funciona de maravilla!

Funciona de maravilla! Gracias por hacer este post tan claro, brindando el paso a paso....es una goleada para los nuevitos! Peter de b&b Venecia

#2

Les femmes bénéficient

Les femmes bénéficient parfois de ce traitement
dans le cadre d'une alopécie féminine diffuse banale mais à une focus inférieure, à
2 %. Il arrive que ce produit entraîne quelques irritations, pellicules ou allergy symptoms.
Il existe des shampoings qui peuvent atténuer les irritations et les démangeaisons.

#3

A quality juicer that works

A quality juicer that works well at lower speeds is the ideal type to look for.
It comes with several features such as the following:. Most lower- and medium-end
juicers on the market use the centrifugal method.

#4

I did look in several of the

I did look in several of the nationally known cookbooks having sections
on baking cookies just to see if any author had the inkling that any of their readers would seek out such an idea.

This will save you both money and time in the long run, with you being
able to get more juice out of each piece of fruit or
vegetable that you put in the machine. Families probably want to
consider a larger juicer.

#5

Hey there! Do you know if

Hey there! Do you know if they make any plugins to assist
with Search Engine Optimization? I'm trying to get my blog to
rank for some targeted keywords but I'm not seeing very good gains.
If you know of any please share. Appreciate it!

#6

You also can learn more about

You also can learn more about the juicer by
understanding its benefits that make it a great choice over the other
juicers in the market. This will save you both money and time in the long
run, with you being able to get more juice out of each piece of fruit or vegetable that you put in the machine.

Families probably want to consider a larger juicer.

#7

Good post. I learn something

Good post. I learn something new and challenging on websites I stumbleupon every day.
It's always useful to read content from other writers and practice a little something from
their websites.

#8

A quality juicer that works

A quality juicer that works well at lower speeds is the ideal type to look for.
This will save you both money and time in the long run, with you being able to get more juice out of
each piece of fruit or vegetable that you put in the machine.
Very few models come close to the efficiency of this one and even if they do, they don't
seem to last as long or produce as much juice.

#9

Hiya! Quick question that's

Hiya! Quick question that's totally off topic.

Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone.
I'm trying to find a template or plugin that might be able to correct this issue.
If you have any suggestions, please share. Appreciate it!

clash of clans hack

#10

As I crossed the street, I

As I crossed the street, I saw a man parked by the donation center
taking a juicer out of his car. The most recent model of the Power Juicer
incorporates soy technology for making high protein drinks and is called the Elite model.
Families probably want to consider a larger juicer.

#11

Thank you for writing this,

Thank you for writing this, it's saved me a ton of time in figuring this out myself. One minor correction, in step 1.2, I think you're if statement shoudl be the following, to prevent loading the plugin for some other module who might also use plugins names 'styles'

if ($plugin == 'styles') {

should be

if ('panels' == $module && 'styles' == $plugin) {

#12

Excelent point Oscar, I have

Excelent point Oscar, I have updated the code in the post, thanks for pointing this out, and glad to hear it saved you time!

#13

This is especially important

This is especially important for low-budget projects. Stone countertops can be anywhere from
$5 to $150 per square foot. During the process of refining the gas,
a chemical known as Mercaptan is added to the gas for it to have a
distinctive odour for safety purposes.

#14

clash of lords 2 Crack Get

clash of lords 2 Crack

Get clash of lords 2 Secrets and cheats in this article!
It is possible to acquire clash of lords 2 Hack with regard to Operating system along with iOS!

clash of lords 2 Compromise creates infinite Jewels, infinite Gold,
unlimited People as well as limitless Rings! Just about all comes in clash of lords 2 tricks through
TopProgramer. com! Protection script interior clash of lords
2 Compromise Device guards your own solitude along with devices.
clash of lords 2 Chop will be day-to-day kept up to date to
help you utilize it once you want sometime soon and it also works!
Great, proper? clash of lords 2 Chop possesses simple to
use screen and is incredibly simple to operate. Crack with regard to clash of lords 2 will
connect to ones Android os or even iOS devices. Improvement works with
most iOS units (iPhone, apple company ipad in addition to ipod touch and also other) without jailbreak.
clash of lords 2 Crack works together with Android at
the same time. clash of lords 2 Crack Instrument doesn’t will need underlying
and is also works with most Android os OPERATING-SYSTEM
designs. Tips on how to work with Hack into clash of
lords 2? Utilize UNIVERSAL SERIES BUS in addition to plug inside system together with clash of
lords 2 in your COMPUTER SYSTEM. Let’s manage Crack clash of lords 2
nevertheless initial obtain the idea via TopProgramer.
com clash of lords 2 crack gives unlimited Jewels, infinite Platinum, endless Souls along
with limitless Wedding rings in order to game!
leading programer (. com)! Acquire clash of lords 2 Crack right now along with engage in without the limitations!
Acquire limitless Jewels, limitless Gold, endless Spirits and unlimited Rings right now!

clash of lords 2 compromise
clash of lords 2 Compromise Functions

#15

You will also need to be

You will also need to be careful with citrus fruit because they have a lot
of citric acid in them. The majority of the vegetable recipes include carrots
as one of the staple ingredients. Most lower- and medium-end juicers on the market use the centrifugal method.

#16

A quality juicer that works

A quality juicer that works well at lower speeds is
the ideal type to look for. All of the parts are easily removed and are made of an easy-to-clean material.
When compared to a centrifugal juicer, you will see
that the juices from this masticating juicer are much darker because of the way it extracts all parts of the vegetable instead of
just the juice.

#17

Hello Dear, are you truly

Hello Dear, are you truly visiting this web site daily, if so after that you will
absolutely obtain fastidious experience.

#18

Heya are using Wordpress for

Heya are using Wordpress for your site platform? I'm new to the blog world but
I'm trying to get started and create my own. Do you require any coding expertise to make
your own blog? Any help would be really appreciated!

#19

You will also need to be

You will also need to be careful with citrus fruit because they have a lot of citric acid
in them. Most high functioning juicers will cost somewhere in the range of $200 to $2,000.
You might think that taking the time to juice your own fruit is time
consuming and wasteful.

#20

I did look in several of the

I did look in several of the nationally known cookbooks having sections on baking cookies just to see if any author had the inkling
that any of their readers would seek out such an idea.
Most high functioning juicers will cost somewhere in the range of $200 to $2,000.
Fruits with high amount of citric acid should be consumed in moderation.

#21

Nine times out of ten

Nine times out of ten computer problems can be resolved quickly and painlessly if you know what steps to take.
Some Game Stops will be able to point you in the right direction, as they will know who is local that can help you with that type
of repair, so I would recommend that you check them out if you don't feel comfortable trying this
PS3 repair on your own. A lot of schools and also colleges on the net provide acquaintances degree applications.

#22

Hiya! I know this is kinda

Hiya! I know this is kinda off topic but I'd figured I'dask.
Would you be interested in exchanging links or maybe guest authoring a blog
post or vice-versa? My website discusses a
lot of the same subjects as yours and I feel we could greatly
benefit from each other. If you are interested feel free to shoot me
an email. I look forward to hearing from you! Terrific blog by the way!

#23

Hi there! Do you know if they

Hi there! Do you know if they make any plugins to help with SEO?
I'm trying to get my blog to rank for some targeted keywords
but I'm not seeing very good gains. If you know of any please share.
Thank you!

#24

I did look in several of the

I did look in several of the nationally known cookbooks having sections on baking cookies just
to see if any author had the inkling that any of their readers
would seek out such an idea. The quality of juice obtained from an orange
juice extractor is not the same as what is mass-produced and sold in stores.

Or would you rather go for low motor speed that will produce
a more quiet juicing process.

#25

Additionally, individual

Additionally, individual web-based companies are working overtime to protect those visiting
their sites. But once you reach the higher levels, it could take days
to make it to the next level. You can still find plenty of people who do not use Facebook specifically because of security worries.

#26

A quality juicer that works

A quality juicer that works well at lower
speeds is the ideal type to look for. The most recent model of the Power Juicer incorporates soy technology for making high protein drinks and is called the Elite model.

Manual press juice extractors are quite difficult to operate.

#27

The next type of juicer is

The next type of juicer is called a masticating juicer because it extracts juice using a repetitive pressing movements.
It comes with several features such as the following:.
Manual press juice extractors are quite difficult to operate.

#28

Very nice article. I

Very nice article. I definitely appreciate this website.
Thanks!

#29

One thing I learned, is for

One thing I learned, is for your style to be available as a region style, you need to define a 'render panel' function, for it to be available as a style for a single pane, defined a 'render pane' function.

#30

I just tried this and now I

I just tried this and now I can't access the panels dashboard. I get the WSOD.

#31

The WSOD is most likely an

The WSOD is most likely an indication that php is runing out of memory on your server. This has nothing to do with what is explained here, but rather a problem with your server's configuration.
Check out this link about what could be causing this: http://drupal.org/node/158043 , but I find that most of the cases this is fixed by increasing memory_limit in your server's php.ini file.

#32

You will also need to be

You will also need to be careful with citrus fruit because they have a
lot of citric acid in them. This will save you both money and time in the long run, with you being able to get more juice
out of each piece of fruit or vegetable that you put in the machine.
Manual press juice extractors are quite difficult to operate.

#33

Tried the above module in D7,

Tried the above module in D7, but no dice. It shows up in the styles menu, but the field never gets collapsed upon viewing it.

#34

The Denver Search Engine

The Denver Search Engine Optimizers at Fusionbox spend
our careers making an attempt to figure out what the algorithm likes best and assist talk that with throughout the design, growth and advertising process.

If there was no seo then webmasters could be enjoying quick
and unfastened with web sites and search algorithms would have a harder
time determining a website's value and authority.

#35

Hi there everyone, it's my

Hi there everyone, it's my first visit at this web site,
and post is in fact fruitful for me, keep up posting these types of content.

#36

Hi I am so happy I found your

Hi I am so happy I found your web site, I really found you by mistake,
while I was browsing on Yahoo for something else, Anyways I
am here now and would just like to say thank you for a marvelous post
and a all round exciting blog (I also love the theme/design),
I don't have time to look over it all at the moment but I have saved
it and also added your RSS feeds, so when I have time I will be
back to read a lot more, Please do keep up the awesome work.

#37

This site was... how do you

This site was... how do you say it? Relevant!! Finally I've
found something which helped me. Thanks a lot!

#38

It is vital that you study

It is vital that you study the market for some time ' at least a month or more '
before actually putting your money in. In order to
try yourself in forex and see if this kind of business fits you, we recommend you to gain some knowledge about the Foreign Exchange Market
first and then practice in demo account with one of
the brokers. If your current computer is not as up to date as you would like it to be and you are not in a position to bring it up to a
faster processing specification or replace it
with a faster workstation, then it is worth considering only using Forex Brokers that operate the ECN platform because this software requires less processing power to run at
full speed as it is simpler software.

#39

of course like your web site

of course like your web site however you have to test the spelling on quite
a few of your posts. A number of them are rife with
spelling issues and I to find it very bothersome to inform the reality then again I'll definitely come
again again.

#40

Some expert in raw food

Some expert in raw food movement say that due to heat,
a centrifuge juicer can destroy all enzymes or a part of them.
The majority of the vegetable recipes include carrots as one of the
staple ingredients. Manual press juice extractors are quite difficult to operate.

#41

Country Music superstar

Country Music superstar singer and songwriter Pam Tillis
shers in a new eera of Christmas at the Galt Home Hotel.

#42

Choroby przewlekłe: cukrzyca

Choroby przewlekłe: cukrzyca typu 1, choroby tarczycy, hipoplazja
szkliwa zębowego, nawrotowe owrzodzenia jamy ustnej (afty), zaburzenia psychiczne, np.

schizofrenia, nowotwory jelita cienkiego, głównie chłoniaki.

#43

In this the fruit and

In this the fruit and vegetables are first ground and then the juice is forwarded with the help of a strainer which revolves at a very high
rpm. Most high functioning juicers will cost somewhere in the range of $200 to $2,000.
Fruits with high amount of citric acid should be
consumed in moderation.

#44

Every weekend i used to visit

Every weekend i used to visit this web page, as i want enjoyment, since this this site conations really nice funny information too.

#45

As I crossed the street, I

As I crossed the street, I saw a man parked by the donation center taking a juicer out of his car.

The most recent model of the Power Juicer incorporates
soy technology for making high protein drinks and
is called the Elite model. When compared to a centrifugal juicer, you will see that the juices from this
masticating juicer are much darker because of the way it extracts
all parts of the vegetable instead of just the juice.

#46

I'm impressed, I have to

I'm impressed, I have to admit. Rarely do I come across a blog
that's both equally educative and engaging, and let me tell
you, you have hit the nail on the head. The issue is an issue that not enough people are speaking intelligently about.

I'm very happy I stumbled across this during my hunt for something concerning
this.

#47

If you have no idea where to

If you have no idea where to begin, don't try it on your own. Checking
for Registry errors is highly recommended.
It means you can study well OR you know a lot about computers.

#48

Aware Bear Computers

Aware Bear Computers (585)473-7035 on 5 Monroe Avenue Pittsford
NY reviewed the new HP ENVY 14 Beats Edition Series.
However if like many computer users, you are uncomfortable with DIY, then remote is not for you.
It can be challenging to find qualified
technician providing affordable services; however, with moderate research and web browsing, you will be able to find
a suitable technician.

#49

For example, the Web Editor I

For example, the Web Editor I use includes a page view for "Source", that may show all the code
with the page. If you want to determine if keyword phrases are giving you achievement and
then add brand new ones, you can refer to the Google Keyword tool.
Another drawback is the method that IT developers connect to these new
databases is via modern programming languages for example
Java, Python, and Perl.

#50

In this the fruit and

In this the fruit and vegetables are first ground and then the juice is forwarded with the help of a strainer which revolves
at a very high rpm. Thus, it is important to remain at top shape so that you can succeed despite the occasional glitch in life.
Fruits with high amount of citric acid should be consumed in moderation.

Post new comment

The content of this field is kept private and will not be shown publicly.
By submitting this form, you accept the Mollom privacy policy.

Languages

Contact