skinr_panels.module in Skinr 7.2
Same filename and directory in other branches
Provides Skinr integration with Panels.
NOTE: When panels are stored in code, rather than DB, we run into lack of context problems. See the below link for a workaround. This is a limitation with the Panels module.
Undefined property: stdClass::$did in panels_skinr_preprocess_index_handler() Workaround for undefined property: stdClass::$did in panels_skinr_preprocess_index_handler()
File
skinr_panels/skinr_panels.moduleView source
<?php
/**
* @file
* Provides Skinr integration with Panels.
*
* NOTE: When panels are stored in code, rather than DB, we run into lack of
* context problems. See the below link for a workaround. This is a limitation
* with the Panels module.
*
* @link http://drupal.org/node/1160924 Undefined property: stdClass::$did in panels_skinr_preprocess_index_handler() @endlink
* @link http://drupal.org/node/1292662 Workaround for undefined property: stdClass::$did in panels_skinr_preprocess_index_handler() @endlink
*/
/**
* Implements hook_skinr_api().
*/
function skinr_panels_skinr_api_2() {
return array();
}
/**
* Implements hook_theme_registry_alter().
*
* Re-order preprocess functions to prioritize skinr_ui_preprocess, which adds
* contextual links, over template_preprocess_HOOK functions. This fixes a
* problem with the way panels handles contextual links.
*/
function skinr_panels_theme_registry_alter(&$theme_registry) {
$preprocess_functions = array();
foreach ($theme_registry['panels_pane']['preprocess functions'] as $function) {
if ($function == 'skinr_ui_preprocess' || $function == 'skinr_panels_preprocess') {
continue;
}
$preprocess_functions[] = $function;
if ($function == 'template_preprocess') {
// Insert our preprocess function right after template_preprocess to give it priority over template_preprocess_HOOK functions.
$preprocess_functions[] = 'skinr_panels_preprocess';
$preprocess_functions[] = 'skinr_ui_preprocess';
}
}
$theme_registry['panels_pane']['preprocess functions'] = $preprocess_functions;
// Add a preprocess function to theme_links(). This is a total hack.
$theme_registry['links']['preprocess functions'][] = 'skinr_panels_preprocess_links';
}
/**
* Implements hook_module_implements_alter().
*/
function skinr_panels_module_implements_alter(&$implementations, $hook) {
if ($hook == 'skinr_preprocess_alter') {
// Make our version of hook_skinr_preprocess_alter() happen before that of
// skinr_context.
$group = $implementations['skinr_panels'];
unset($implementations['skinr_panels']);
$implementations = array_reverse($implementations, TRUE);
$implementations['skinr_panels'] = $group;
$implementations = array_reverse($implementations, TRUE);
}
}
/**
* Implements hook_page_build().
*/
function skinr_panels_page_build(&$page) {
// Any blocks added before this hook is called are in panels.
_skinr_panels_is_panel(FALSE);
}
/**
* Helper function to determine wether or not a panel is being rendered.
*/
function _skinr_panels_is_panel($page_build = NULL) {
static $is_panel = TRUE;
if (!is_null($page_build)) {
$is_panel = FALSE;
}
return $is_panel;
}
/**
* Implements hook_skinr_preprocess_alter().
*/
function skinr_panels_skinr_preprocess_alter(&$skins, $context) {
if (module_exists('skinr_context') && ($context['hook'] == 'panels_pane' || _skinr_panels_is_panel() && $context['hook'] == 'block')) {
foreach ($skins as $key => $skin) {
if (!empty($skin->gid) && ($group = skinr_context_group_load($skin->gid))) {
// Set group based weight on skins.
$skin->weight = $group->weight;
}
}
// Reorder by weight.
uasort($skins, 'skinr_context_sort_weight');
// Set placeholders.
foreach ($skins as $skin) {
$placeholder = skinr_panels_set_skin_options($skin);
$context['variables']['classes_array'][] = $placeholder;
}
// Don't pass along any skins. We'll process them later.
$skins = array();
}
}
/**
* Helper function to retrieve stored skin options.
*/
function skinr_panels_get_skin_options() {
return skinr_panels_set_skin_options();
}
/**
* Helper function to store skin options for later retrieval.
*/
function skinr_panels_set_skin_options($skin = NULL, $reset = FALSE) {
static $counter = 0;
static $cache = array();
if ($reset) {
$cache = array();
}
if (!is_null($skin)) {
$placeholder = 'skinr_placeholder_' . $counter++;
$cache[$placeholder] = clone $skin;
return $placeholder;
}
return $cache;
}
/**
* Implements hook_preprocess_page().
*/
function skinr_panels_preprocess_page(&$variables) {
if (module_exists('skinr_context')) {
if ($skins = skinr_panels_get_skin_options()) {
$contexts = context_active_contexts();
$search = array_keys($skins);
$replace = array();
foreach ($skins as $placeholder => $skin) {
if (!empty($skin->gid) && ($group = skinr_context_group_load($skin->gid))) {
// Remove skins for groups that arent in the right context.
if (!isset($contexts['skinr_group__' . $skin->gid])) {
$replace[] = '';
}
else {
$classes_array = skinr_flatten_skins_array(array(
$skin->skin => $skin->options,
));
$replace[] = implode(' ', $classes_array);
}
}
}
$is_node = isset($variables['node']) && $variables['node']->type == 'panel' && module_exists('panels_node');
$is_page = isset($variables['page']);
if ($is_node) {
// Panel node page.
$panel =& $variables['page']['content']['system_main']['nodes'][$variables['node']->nid]['body']['#markup'];
}
elseif ($is_page) {
// Panel page.
$panel =& $variables['page']['content']['system_main']['content']['#markup'];
}
$panel = str_replace($search, $replace, $panel);
}
}
}
Functions
Name | Description |
---|---|
skinr_panels_get_skin_options | Helper function to retrieve stored skin options. |
skinr_panels_module_implements_alter | Implements hook_module_implements_alter(). |
skinr_panels_page_build | Implements hook_page_build(). |
skinr_panels_preprocess_page | Implements hook_preprocess_page(). |
skinr_panels_set_skin_options | Helper function to store skin options for later retrieval. |
skinr_panels_skinr_api_2 | Implements hook_skinr_api(). |
skinr_panels_skinr_preprocess_alter | Implements hook_skinr_preprocess_alter(). |
skinr_panels_theme_registry_alter | Implements hook_theme_registry_alter(). |
_skinr_panels_is_panel | Helper function to determine wether or not a panel is being rendered. |