-
-
Save agentolivia/5745929 to your computer and use it in GitHub Desktop.
Example of CTools Style Plugin dot inc file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defines a style plugin | |
* | |
* - panesandblocks: corresponds to directory name of plugin | |
* - render pane: the suffix of the theme function for the pane (without "theme_"). | |
* - Example: If the function name is "theme_panesandblocks_render_pane", | |
* the value of "render pane" is "panesandblocks_render_pane". | |
* - render region: the suffix of the theme function for the region (without "theme_"). | |
* - Example: If the function name is "theme_panesandblocks_render_region", | |
* the value of "render region" is "panesandblocks_render_region". | |
* - pane settings form: name of function that returns a settings form | |
* - hook theme: array of hook theme information | |
* - define an array for pane and region. The key must match the first parameter of the returned theme() in the | |
* corresponding theme_ function. | |
* Example: 'hook theme' => 'panesandblocks_theme_pane' => array(); | |
* In function theme_panesandblocks_render_pane: | |
* return theme('panesandblocks_theme_pane'...) [truncated] | |
* - template: corresponds to name of tpl.php for pane, i.e. panesandblocks-pane.tpl.php | |
* - path: the path where the template file lives | |
* - variables: an array of variables to add to the $variables array in the theme function | |
* | |
*/ | |
$plugin = array( | |
'panesandblocks' => array( | |
'title' => t('My Custom Pane Styles'), | |
'description' => t('Simple styles that highlight sections of your page.'), | |
'render pane' => 'panesandblocks_render_pane', | |
'render region' => 'panesandblocks_render_region', | |
'pane settings form' => 'panesandblocks_settings_form', | |
'hook theme' => array( | |
'panesandblocks_theme_pane' => array( | |
'template' => 'panesandblocks-pane', | |
'path' => drupal_get_path('module', 'name_of_module') .'/plugins/styles/panesandblocks', | |
'variables' => array( | |
'content' => NULL, | |
'settings' => NULL, | |
), | |
), | |
'panesandblocks_theme_region' => array( | |
'template' => 'panesandblocks-region', | |
'path' => drupal_get_path('module', 'name_of_module') .'/plugins/styles/panesandblocks', | |
'variables' => array( | |
'content' => NULL, | |
), | |
), | |
), | |
), | |
); | |
function theme_panesandblocks_render_pane($vars) { | |
$settings = $vars['settings']; | |
$content = $vars['content']; | |
return theme('panesandblocks_render_pane', array('content' => $content, 'settings' => $settings)); | |
} | |
function theme_panesandblocks_render_region($vars) { | |
$content = ''; | |
foreach ($vars['panes'] as $pane_id => $pane_output) { | |
$content .= $pane_output; | |
} | |
if (empty($content)) { | |
return; | |
} | |
return theme('panesandblocks_render_region', array('content' => $content)); | |
} | |
function panesandblocks_settings_form($style_settings) { | |
$options = array( | |
'pane-nostyle' => t('Plain / no styles / transparent background'), | |
'pane-patterned' => t('Patterned'), | |
'pane-reverse' => t('Reverse color values'), | |
'callout-orange' => t('Callout: Orange'), | |
'callout-blue' => t('Callout: Blue') | |
); | |
$headings = array( | |
'pane-heading-default' => t('Describe Default Heading Style Here'), | |
'pane-heading-secondary' => t('Describe Secondary Heading Style Here'), | |
'pane-heading-tertiary' => t('Describe Tertiary Heading Style Here') | |
); | |
$form['css_classes'] = array( | |
'#type' => 'radios', | |
'#title' => t('Custom Pane and Block Styles'), | |
'#description' => t('Choose a style for your pane or block.'), | |
'#options' => $options, | |
'#required' => FALSE, | |
'#default_value' => (isset($style_settings['css_classes'])) ? $style_settings['css_classes'] : 'pane-nostyle', | |
); | |
$form['heading_classes'] = array( | |
'#type' => 'radios', | |
'#title' => t('Header Styles'), | |
'#description' => t('Choose a header style for your pane or block.'), | |
'#options' => $headings, | |
'#required' => FALSE, | |
'#default_value' => (isset($style_settings['heading_classes'])) ? $style_settings['heading_classes'] : '', | |
); | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment