You are here

function block_class_preprocess_block in Block Class 8

Same name and namespace in other branches
  1. 6.2 block_class.module \block_class_preprocess_block()
  2. 6 block_class.module \block_class_preprocess_block()
  3. 7.2 block_class.module \block_class_preprocess_block()
  4. 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, []);
      }
    }
  }
}