Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Panels has this super useful code that other modules can use to add or remove classes to the body tag:
/**
* Remove default sidebar related body classes and provide own css classes
*/
function panels_preprocess_html(&$vars) {
$panel_body_css = &drupal_static('panel_body_css');
if (!empty($panel_body_css['body_classes_to_remove'])) {
$classes_to_remove = explode(' ', $panel_body_css['body_classes_to_remove']);
foreach ($vars['classes_array'] as $key => $css_class) {
if (in_array($css_class, $classes_to_remove)) {
unset($vars['classes_array'][$key]);
}
}
}
if (!empty($panel_body_css['body_classes_to_add'])) {
$vars['classes_array'][] = check_plain($panel_body_css['body_classes_to_add']);
}
}
I think it would be really nice if this functionality was available for many more modules to use in CTools. I've adapted my custom functions and converted them to CTools.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1775660-class-helpers.patch | 2.8 KB | Dave Reid |
Comments
Comment #1
Dave ReidPatch attached for initial review and approval before I continue with writing tests and/or re-rolling for Drupal 8.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedOkay, I'm feeling really bad for not having seen this earlier!
Committed and pushed. We will probalby want to retool Panels to use this instead, but we have to be wary because we don't want to just break people who update Panels but not CTools.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedOh incidentally I also upped the CTools API version and edited API.txt to mention the introduction of the new functions.
Comment #5
andypostThe issue introduces huge performance regression and was commited within #1763746: Double returns in user_edit argument.
ctools_process() is called for each renderable and most of this calls are useless.
Suppose better to revert commit http://drupalcode.org/project/ctools.git/commit/12d6b1d and then commit actual changes from #1763746: Double returns in user_edit argument.
Comment #6
MustangGB CreditAttribution: MustangGB commentedI'm guessing this is solved by now as there doesn't appear to be any huge performance issues presently.