function block_class_preprocess_block in Block Class 8
Same name and namespace in other branches
- 6.2 block_class.module \block_class_preprocess_block()
- 6 block_class.module \block_class_preprocess_block()
- 7.2 block_class.module \block_class_preprocess_block()
- 7 block_class.module \block_class_preprocess_block()
Implements hook_preprocess_HOOK().
File
- ./
block_class.module, line 76 - Adding classes to blocks.
Code
function block_class_preprocess_block(&$variables) {
// Blocks coming from page manager widget does not have id.
if (!empty($variables['elements']['#id'])) {
$block = Block::load($variables['elements']['#id']);
if ($block && ($classes = $block
->getThirdPartySetting('block_class', 'classes'))) {
$classes_array = explode(' ', $classes);
foreach ($classes_array as $class) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier($class, []);
}
}
}
}