Skip to content

Instantly share code, notes, and snippets.

@ndeet
Last active February 8, 2018 14:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ndeet/8998990 to your computer and use it in GitHub Desktop.
Save ndeet/8998990 to your computer and use it in GitHub Desktop.
Drupal 7, Panels 3.3+ Pane Style Plugin
.grey {
background-color: #CCC;
color: black;
}
.yellow {
background-color: yellow;
border: 1px solid red;
}
.pink {
background-color: deeppink;
color: white;
font-size: 120%;
h2 {
text-transform: uppercase;
}
}
<?php
/**
* @file
* Custom panels color presets.
*/
// Plugin registrieren
$plugin = array(
'title' => t('Color preset'),
'description' => t('Set a color preset.'),
// Achtung: render pane wird im Methodenaufruf mit "theme_" prefixed!
'render pane' => 'MYTHEME_color_preset_style_render_pane',
'pane settings form' => 'MYTHEME_color_preset_settings_form',
'category' => t('MYTHEME'),
);
/**
* Renders the pane content.
*/
function theme_MYTHEME_color_preset_style_render_pane($content) {
if (!empty($content)) {
return theme('panels_pane', $content);
}
}
/**
* Color preset settings form.
*/
function MYTHEME_color_preset_settings_form($style_settings) {
$form = array();
$form['preset_color'] = array(
'#type' => 'select',
'#title' => t('Choose color preset'),
'#default_value' => (isset($style_settings['preset_color'])) ? $style_settings['preset_color'] : FALSE,
'#options' => theme_MYTHEME_color_preset_colors(),
);
return $form;
}
/**
* Available color presets.
* @return array
*/
function theme_MYTHEME_color_preset_colors() {
return array(
'grey' => t('Grey'),
'yellow' => t('Yellow'),
'pink' => t('Pink')
// etc.
);
}
; Register Style Plugin directory
plugins[panels][styles] = panels/styles
<?php
/**
* @file
* Preprocess panels color presets.
*/
/**
* Implements hook_preprocess_panels_pane().
*/
function MYTHEME_preprocess_panels_pane(&$variables) {
// Prüfen ob unser Style Plugin aktiv ist.
if(isset($variables['pane']->style['style'])) {
if($variables['pane']->style['style'] === 'color_presets') {
// Setzt die in o.g. theme_MYTHEME_preset_colors definierte Farbe als CSS-Klasse
$variables['attributes_array']['class'][] = $variables['pane']->style['settings']['preset_color'];
}
}
return $variables;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment