You are here

function closeblock_preprocess_block in Close Block 8

Implements hook_preprocess_HOOK().

File

./closeblock.module, line 33
Module's hooks implementations.

Code

function closeblock_preprocess_block(&$variables) {
  $permission = \Drupal::currentUser()
    ->hasPermission('close block');
  if ($permission) {
    if (!empty($variables['elements']['#id'])) {
      $block = Block::load($variables['elements']['#id']);
      if ($block instanceof ThirdPartySettingsInterface) {
        $settings = $block
          ->getThirdPartySetting('closeblock', 'closeblock_active');
        if ($settings) {
          $variables['attributes']['class'][] = Html::cleanCssIdentifier('close-block', []);
          $variables['#attached']['library'][] = 'closeblock/closeblock';
        }
      }
    }
  }
}