Write a Custom Panel for Page Manager in Drupal 7

Page Manager allows you to build up a “page” with smaller “panels”, such that you can add fields, blocks and views into different layouts. But how do you write your own custom panel?

Page Manager is a part of the Chaos Tools module.

Register a Plugin Directory

Create this function in your modules .module file. This simply tells cTools where to look for additional plugins.

Remember that Chaos Tools uses the term “Content Types” differently to the Drupal Core.

function XXX_ctools_plugin_directory($owner, $plugin_type) {
    if ($owner == 'ctools' && $plugin_type == 'content_types') {
        return 'plugins/' . $plugin_type;

You will also need to create a directiory in your module called “plugins/content_types”.

Create a Plugin Definition

Each plugin will have its own file – for example PLUGINNAME.inc – with this structure.

$plugin = array(
    'title' => t('Your Title Goes Here'),
    'single' => TRUE,
    'category' => array(t('Custom')),
    'content_type' => 'XXX_PLUGINNAME',
    'required context' => new ctools_context_required(t('Node'), 'node'),

Other options are

  • edit form
  • render callback
  • optional context

You main output function is

function XXX_PLUGINNAME_content_type_render($subtype, $conf, $panel_args, $context) {
    $block = new stdClass();
    $block -> title = "Your Display Title Goes Here";
    $block -> content .= "Add some HTML content";"
    return $block;

The $panel_args variable is an array of contextual variables that you can use

$sensorid = $panel_args[0];

Leave a comment