Content types are the snippets of content which you put into your panels. These are big things like views, CCK elements and widgets like the 'contact form' provided by the Contact module.
Not all modules integrate with panels – in other words, they don't necessarily provide all their bits of content as snippets to panels. In this case you can write your own plugin to do this.
Lets take a really simple example. There is in fact a 'logo' content type in the main ctools/panels offering, but in our case we like to wrap it in <h1> tags and put a few keywords as the alternative text. Normally you'd do that in your page.tpl.php – but if you are inserting the logo in a panel which is completely in charge of the page, then you can't do that. So in this case this code is copied from the ctools > plugins > content_types > page folder – the file is page_logo.inc.
First you need to make sure you create a folder called 'content_types' inside your ctools folder and implement hook_ctools_plugin_directory (see the context stuff for that). If this is in the same module as the contexts, all you need to do is create the folder.
Then you create your file called 'MYPLUGIN.inc' where MYPLUGIN is the name of your plugin. Ours is called 'olamalu_extra_logo.inc'.
$plugin = array(
'title' => t('Olamalu adapted logo'),
'single' => TRUE,
'icon' => 'icon_page.png',
'description' => t('Add the logo trail as content – ours is wrapped in H1.'),
'category' => t('Page elements'),
'render last' => TRUE,
// Constructor.
'content_types' => array('olamalu_panels_extra_logo'),
// Name of a function which will render the block.
'render callback' => 'olamalu_panels_extra_logo_render',
);
/**
* Output function for the 'olamalu_panels_extra_logo' content type.
*
* Outputs the logo for the current page with the site name and slogan as title.
*/
function olamalu_panels_extra_logo_render($subtype, $conf, $panel_args) {
$logo = theme_get_setting('logo');
if (!empty($logo)) {
$block = new stdClass();
$title = check_plain(variable_get('site_name', "Home")) . ' '. check_plain(variable_get('site_slogan', ""));
$image = '<img src="' . $logo . '" alt="' . $title . '" />';
$block->content = '<h1>' . l($image, '', array('html' => TRUE, 'attributes' => array('rel' => 'home', 'id' => 'logo', 'title' => $title))) . '</h1>';
}
return $block;
}
The $plugins array defines this according to the ctools pattern – you need a title and description. The category is the tab on the side of adding content types into which your widget will go. Ours goes into the 'page elements' with the other page related stuff. The content_types is your content type unique name and the render callback is the function which will return a rendered HTML string.
This is implemented just below. In our case it simply takes the logo, gets the site slogan (where we store keywords) and wraps the logo in H1 tags with the alternative text being the site slogan. It sets the
$block->content to that HTML output and returns the $block.
Flush the cache and you'll see your content type!
Little note: If you really want to see how plugins are programmed in lots of ways, then the best place is to look in the ctools code. Go to the ctools > plugins folder – in there you will see all the plugins in all the different guises.