You are here

public function BlockStyleBase::build 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::build()

Builds and returns the renderable array for this block style plugin.

Parameters

array $variables: List of all variables sent to the theme system.

Return value

array A renderable array representing the content of the block.

Overrides BlockStyleInterface::build

File

src/Plugin/BlockStyleBase.php, line 235

Class

BlockStyleBase
Base class for Block style plugins.

Namespace

Drupal\block_style_plugins\Plugin

Code

public function build(array $variables) {
  $styles = $this
    ->getStylesFromVariables($variables);
  if ($styles) {

    // Add all styles config to the $variables array.
    $variables['block_styles'][$this->pluginId] = $styles;

    // Add each style value as a class.
    foreach ($styles as $class) {

      // Don't put a boolean from a checkbox as a class.
      if (is_int($class)) {
        continue;
      }
      $variables['attributes']['class'][] = $class;
    }
  }
  return $variables;
}