You are here

protected function BlockStyleBase::getStylesFromVariables in Block Style Plugins 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/BlockStyleBase.php \Drupal\block_style_plugins\Plugin\BlockStyleBase::getStylesFromVariables()

Get styles for a block set in a preprocess $variables array.

Parameters

array $variables: Block variables coming from a preprocess hook.

Return value

array|false Return the styles array or FALSE

2 calls to BlockStyleBase::getStylesFromVariables()
BlockStyle::themeSuggestion in src/Plugin/BlockStyle.php
Add theme suggestions for the block.
BlockStyleBase::build in src/Plugin/BlockStyleBase.php
Builds and returns the renderable array for this block style plugin.

File

src/Plugin/BlockStyleBase.php, line 405

Class

BlockStyleBase
Base class for Block style plugins.

Namespace

Drupal\block_style_plugins\Plugin

Code

protected function getStylesFromVariables(array $variables) {

  // Ensure that we have a block id.
  if (empty($variables['elements']['#id'])) {
    return FALSE;
  }

  // Load the block config entity.

  /** @var \Drupal\block\Entity\Block $block */
  $block = $this->entityTypeManager
    ->getStorage('block')
    ->load($variables['elements']['#id']);
  $styles = $block
    ->getThirdPartySetting('block_style_plugins', $this->pluginId);
  if ($styles) {
    $this
      ->setConfiguration($styles);
    return $styles;
  }
  else {
    return FALSE;
  }
}