I love the styles plugin, and I've been using it to create custom panel pane and region styles, but I am trying to include a settings form for a style, and I'm afraid I can't get it to work for reasons I don't understand.

I've created an include file for my new style which is getting picked up. Everything works except the settings form doesn't appear. Is it possible to define a style settings form within a theme? If so, could you let me know what I'm doing incorrectly?
Thank you!

$plugin = array(
  'title' => t('Collapsible'),
  'description' => t('Display a pane that may be collapsed.'),
  'render pane' => 'innovate_collapsible_style_render_pane',
  'settings form' => 'innovate_collapsible_settings_form',
);

function theme_innovate_collapsible_style_render_pane($vars) {
 //Formatting
}

function innovate_collapsible_settings_form($style_settings) {
  $form = array();
  $form['pane_collapsed'] = array(
    '#type' => 'checkbox',
    '#title' => t('Collapsed by default'),
    '#default_value' => (isset($style_settings['pane_collapsed'])) ? $style_settings['pane_collapsed'] : FALSE
  );
  return $form;
}

Comments

merlinofchaos’s picture

Styles evolved in kind of a clunky way. I believe you need 'pane settings form' -- 'settings form' goes to regions.

jastraat’s picture

Yes! That was exactly the problem. Thank you!

jastraat’s picture

Status: Active » Closed (fixed)
mistermastermatt’s picture

Status: Closed (fixed) » Fixed

Hello, I was very excited when I found this post as collapsible panes is exactly what I'm after (for 7.x) but I'm afraid I'm still pretty new to Drupal and don't know how to implement what you've described. Is it possible you (or anyone) could give a more step by step guide? I appreciate it's probably a tall request, but I thought I'd ask.
Many thanks.

Status: Fixed » Closed (fixed)

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

jastraat’s picture

So, this is an example of implementing a panels style - specifically on an individual pane vs. a region. I'm just using the existing ctools theme function to generate the classes.

To add panels styles through your theme, you need to add a line to your theme .info file:

plugins[panels][styles] = panels/styles

'panels/styles' should be the path to the directory where you put your style include files.

I created an include file called 'collapsible.inc' in the directory as named above.
Example code:

/**
 * @file
 * Definition of a collapsible panel pane.
 */

// Plugin definition
$plugin = array(
  'title' => t('Collapsible'),
  'description' => t('Display a pane that may be collapsed.'),
  'render pane' => 'innovate_collapsible_style_render_pane',
  'pane settings form' => 'innovate_collapsible_settings_form',
);

/**
 * Render callback.
 *
 * @ingroup themeable
 */
function theme_innovate_collapsible_style_render_pane($vars) {
  $content = $vars['content'];
  $pane = $vars['pane'];
  $display = $vars['display'];
  $settings = $vars['settings'];

  if (empty($content->content)) {
    return;
  }
  if (!empty($content->title) && $content->content != '') {
    ctools_include('collapsible.theme');

    if (empty($settings['pane_collapsed'])) {
      $settings['pane_collapsed'] = FALSE;
    }
    $output = '<div class="panel-inner pane-inner panel-pane-collapsible">';
    $output .= theme_ctools_collapsible(array('handle' => $content->title, 'content' => $content->content, 'collapsed' => $settings['pane_collapsed']));
    $output .= '</div>';
  }
  else {
    $output = theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
  }

  return $output;
}

/**
 * Settings form callback.
 */
function innovate_collapsible_settings_form($style_settings) {
  $form = array();
  $form['pane_collapsed'] = array(
    '#type' => 'checkbox',
    '#title' => t('Collapsed by default'),
    '#default_value' => (isset($style_settings['pane_collapsed'])) ? $style_settings['pane_collapsed'] : FALSE
  );

  return $form;
}

'innovate' is my theme name, so you would replace that with whatever your theme name is.

mistermastermatt’s picture

Thank you very much, I really appreciate you taking the time to help me out. Worked like a charm.