I've created a number of mini panels. Using the 'export' and 'import' forms it's possible to, well, export and import mini panels. This works quite well. However I now want to put them in code.

I've created an implementation of hook_default_panels_mini() and put my exported code in that. I can see the mini panels in the list at admin/build/panel-mini. When I clicked the 'revert' link for a mini panel, the panel remained in the list, but now it no longer renders and if I try to export it the export code does not match that in my hook_default_panels_mini(). If I take the exported code and manually paste it into the import form at admin/build/panel-mini/import everything works, so I'm confident it's not a fault of the code exported, but rather of the code which handles the reading in of mini panels from code.

The export dump of a mini-panel read in from code is:

$mini = new stdClass;
$mini->disabled = FALSE; /* Edit this to true to make a default mini disabled initially */
$mini->api_version = 1;
$mini->name = 'education_resources';
$mini->category = 'Front page mini panels';
$mini->title = 'Education resources';
$mini->requiredcontexts = FALSE;
$mini->contexts = FALSE;
$mini->relationships = FALSE;
$display = new ;
$display->layout = '';
$display->layout_settings = '';
$display->panel_settings = '';
$display->cache = '';
$display->title = '';
$display->hide_title = FALSE;
$display->content = array();
$display->panels = array();
$mini->display = $display;

Note the empty strings and arrays - these are correctly populated in the original exported code.

This only affects mini panels. For panel pages everything works as expected.

CommentFileSizeAuthor
#4 530104.patch599 bytesstella

Comments

stella’s picture

Oh I'm using the latest ctools module, checked out of CVS today, and I have run update.php.

merlinofchaos’s picture

Status: Active » Closed (works as designed)

I really need to update the documentation.

You need to implement hook_ctools_plugin_api($module, $api) so that it will read your stuff. This is similar to the Views function that can be used to keep APIs in sync. Also it can be used to put the defaults into their own file for easy storage. Here's a sample:

/**
 * Implementation of hook_ctools_plugin_api().
 */
function ptest_ctools_plugin_api($module, $api) {
  if ($module == 'panels_mini' && $api == 'panels_default') {
    return array('version' => 1);
  }
  if ($module == 'page_manager' && $api == 'pages_default') {
    return array('version' => 1);
  }
}
stella’s picture

Status: Closed (works as designed) » Active

The hook is implemented. The panels are detected - they just appear to be partially loaded however.

stella’s picture

Status: Active » Needs review
StatusFileSize
new599 bytes

merlin figured out the problem almost immediately once we chatted about it in IRC. Here's the resulting patch which fixes the problem for me. Thanks!!

Cheers,
Stella

elstudio’s picture

Patch also works for me. Thanks!

merlinofchaos’s picture

Status: Needs review » Fixed

Committed! Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Veggieryan’s picture

Can someone clarify the format needed to define mini panels in code?

<?php
/**
* Implementation of hook_ctools_plugin_api().
*/
function ptest_ctools_plugin_api($module, $api) {
  if ($module == 'panels_mini' && $api == 'panels_default') {
    return array('version' => 1);
  }
  if ($module == 'page_manager' && $api == 'pages_default') {
    return array('version' => 1);
  }
}
?>

looks good, but what is the name and format of the default .inc file for mini panels?

can anyone provide a working example?

merlinofchaos’s picture

Create a mini panel and use the bulk export module; it will provide all the working code you need, tailored to your mini panel.

Veggieryan’s picture

Thanks for your help,
I can import the code via the import form, no problem.
I am looking to include a mini panel in a module but the example in ctools doesnt quite work..
here is an example:
the first panel is a page and it works fine, the second is a mini panel which does not show up.



function example_panels_default_page_manager_pages() {

 $page = new stdClass;
$page->disabled = FALSE; /* Edit this to true to make a default page disabled initially */
$page->api_version = 1;
$page->name = 'our_shows';
$page->task = 'page';
$page->admin_title = 'Our Shows';
$page->admin_description = '';
$page->path = 'our_shows';
$page->access = array();
$page->menu = array();
$page->arguments = array();
$page->conf = array();
$page->default_handlers = array();
$handler = new stdClass;
$handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
$handler->api_version = 1;
$handler->name = 'page_our_shows_panel_context';
$handler->task = 'page';
$handler->subtask = 'our_shows';
$handler->handler = 'panel_context';
$handler->weight = 0;
$handler->conf = array(
  'title' => 'Panel',
  'no_blocks' => FALSE,
  'css_id' => '',
  'css' => '',
  'contexts' => array(),
  'relationships' => array(),
);
$display = new panels_display;
$display->layout = 'flexible';
$display->layout_settings = array(
  'items' => array(
    'canvas' => array(
      'type' => 'row',
      'contains' => 'column',
      'children' => array(
        '0' => 'main',
      ),
      'parent' => NULL,
    ),
    'main' => array(
      'type' => 'column',
      'width' => 100,
      'width_type' => '%',
      'children' => array(
        '0' => 'main-row',
      ),
      'parent' => 'canvas',
    ),
    'main-row' => array(
      'type' => 'row',
      'contains' => 'region',
      'children' => array(
        '0' => 'left',
        '1' => 'center',
      ),
      'parent' => 'main',
    ),
    'center' => array(
      'type' => 'region',
      'title' => 'Center',
      'width' => '100',
      'width_type' => '%',
      'parent' => 'main-row',
    ),
    'left' => array(
      'type' => 'region',
      'title' => 'Left',
      'width' => '220',
      'width_type' => 'px',
      'parent' => 'main-row',
    ),
  ),
);
$display->panel_settings = array(
  'center' => array(
    'style' => '-1',
  ),
  'style_settings' => array(),
);
$display->cache = array();
$display->title = 'Our Shows';
$display->hide_title = TRUE;
$display->content = array();
$display->panels = array();
  $pane = new stdClass;
  $pane->pid = 'new-1';
  $pane->panel = 'center';
  $pane->type = 'views';
  $pane->subtype = 'homepage_featured_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 0,
    'link_to_view' => 0,
    'args' => '',
    'url' => '',
    'display' => 'block_1',
    'override_title' => 1,
    'override_title_text' => 'Featured Shows',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 0;
  $display->content['new-1'] = $pane;
  $display->panels['center'][0] = 'new-1';
  $pane = new stdClass;
  $pane->pid = 'new-2';
  $pane->panel = 'center';
  $pane->type = 'panels_mini';
  $pane->subtype = 'our_shows_tabs';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'override_title' => 1,
    'override_title_text' => 'Popular Shows',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 1;
  $display->content['new-2'] = $pane;
  $display->panels['center'][1] = 'new-2';
  $pane = new stdClass;
  $pane->pid = 'new-3';
  $pane->panel = 'left';
  $pane->type = 'block';
  $pane->subtype = 'taxonomy_list-7';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'override_title' => 1,
    'override_title_text' => 'Categories',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 0;
  $display->content['new-3'] = $pane;
  $display->panels['left'][0] = 'new-3';
$handler->conf['display'] = $display;
$page->default_handlers[$handler->name] = $handler;
  $pages['our_shows'] = $page;




/*Tabs for the our shows page*/

$mini = new stdClass;
$mini->disabled = FALSE; /* Edit this to true to make a default mini disabled initially */
$mini->api_version = 1;
$mini->name = 'our_shows_tabs';
$mini->category = 'our shows';
$mini->title = 'Our Shows Tabs';
$mini->requiredcontexts = FALSE;
$mini->contexts = FALSE;
$mini->relationships = FALSE;
$display = new panels_display;
$display->layout = 'onecol';
$display->layout_settings = array();
$display->panel_settings = array(
  'middle' => array(
    'style' => 'tabs',
  ),
  'style_settings' => array(
    'middle' => array(
      'filling_tabs' => 'equal',
    ),
  ),
);
$display->cache = array();
$display->title = '';
$display->hide_title = FALSE;
$display->content = array();
$display->panels = array();
  $pane = new stdClass;
  $pane->pid = 'new-1';
  $pane->panel = 'middle';
  $pane->type = 'views';
  $pane->subtype = 'example_our_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 1,
    'link_to_view' => 0,
    'args' => 'biographies',
    'url' => '',
    'display' => 'page_1',
    'override_title' => 1,
    'override_title_text' => 'Biographies',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 0;
  $display->content['new-1'] = $pane;
  $display->panels['middle'][0] = 'new-1';
  $pane = new stdClass;
  $pane->pid = 'new-2';
  $pane->panel = 'middle';
  $pane->type = 'views';
  $pane->subtype = 'example_our_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 1,
    'link_to_view' => 0,
    'args' => 'entertainment',
    'url' => '',
    'display' => 'page_1',
    'override_title' => 1,
    'override_title_text' => 'Entertainment',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 1;
  $display->content['new-2'] = $pane;
  $display->panels['middle'][1] = 'new-2';
  $pane = new stdClass;
  $pane->pid = 'new-3';
  $pane->panel = 'middle';
  $pane->type = 'views';
  $pane->subtype = 'example_our_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 1,
    'link_to_view' => 0,
    'args' => 'music',
    'url' => '',
    'display' => 'page_1',
    'override_title' => 1,
    'override_title_text' => 'Music',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 2;
  $display->content['new-3'] = $pane;
  $display->panels['middle'][2] = 'new-3';
  $pane = new stdClass;
  $pane->pid = 'new-4';
  $pane->panel = 'middle';
  $pane->type = 'views';
  $pane->subtype = 'example_our_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 1,
    'link_to_view' => 0,
    'args' => 'comedy',
    'url' => '',
    'display' => 'page_1',
    'override_title' => 1,
    'override_title_text' => 'Comedy',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 3;
  $display->content['new-4'] = $pane;
  $display->panels['middle'][3] = 'new-4';
  $pane = new stdClass;
  $pane->pid = 'new-5';
  $pane->panel = 'middle';
  $pane->type = 'views';
  $pane->subtype = 'example_our_shows';
  $pane->shown = TRUE;
  $pane->access = array();
  $pane->configuration = array(
    'nodes_per_page' => '10',
    'pager_id' => '1',
    'use_pager' => 0,
    'offset' => '0',
    'more_link' => 0,
    'feed_icons' => 0,
    'panel_args' => 1,
    'link_to_view' => 0,
    'args' => 'inside stories',
    'url' => '',
    'display' => 'page_1',
    'override_title' => 1,
    'override_title_text' => 'Inside Stories',
  );
  $pane->cache = array();
  $pane->style = array();
  $pane->css = array();
  $pane->extras = array();
  $pane->position = 4;
  $display->content['new-5'] = $pane;
  $display->panels['middle'][4] = 'new-5';
  $mini->display = $display;
  
    $pages['our_shows_tabs'] = $page;


// END PAGE EXPORT ******************************************************/
 
  return $pages;
}
merlinofchaos’s picture

Seriously, the bulk export tool provides all the module hooks too. Try it.