You are here

function _block_styles_get_style in Block Styles 1.x

Same name and namespace in other branches
  1. 8 block_styles.module \_block_styles_get_style()
  2. 2.x block_styles.module \_block_styles_get_style()
3 calls to _block_styles_get_style()
block_styles_form_block_form_alter in ./block_styles.module
Implements hook_form_alter() adding administration for block layouts.
block_styles_preprocess_block in ./block_styles.module
Implements hook_preprocess_block() for blocks.
block_styles_theme_suggestions_block_alter in ./block_styles.module
Implements hook_theme_suggestions_HOOK_alter() for block templates.

File

./block_styles.module, line 151

Code

function _block_styles_get_style($block_id) {
  if (!$block_id) {
    return false;
  }
  $block_styles_storage = \Drupal::entityTypeManager()
    ->getStorage('block_styles');
  $block = $block_styles_storage
    ->load($block_id);
  if (isset($block)) {
    $styles_manager = \Drupal\styles_api\Style::stylePluginManager();
    $plugin_definitions = $styles_manager
      ->getDefinitions();
    $block_theme = $block
      ->get('theme');
    if (!empty($plugin_definitions[$block_theme])) {
      $provider_type = $plugin_definitions[$block_theme]['provider_type'];
      $provider = $plugin_definitions[$block_theme]['provider'];
      if ($provider_type == 'theme') {
        $theme = \Drupal::theme()
          ->getActiveTheme()
          ->getName();
        if ($theme != $provider) {
          return false;
        }
      }
    }
    return $block
      ->getStyle();
  }
}