You are here

public function BlockStyle::themeSuggestion in Block Style Plugins 8

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

Add theme suggestions for the block.

Parameters

array $suggestions: List of theme suggestions.

array $variables: List of variables from a preprocess hook.

Return value

array List of all theme suggestions.

Overrides BlockStyleBase::themeSuggestion

File

src/Plugin/BlockStyle.php, line 50

Class

BlockStyle
Provides a default class for block styles declared by yaml.

Namespace

Drupal\block_style_plugins\Plugin

Code

public function themeSuggestion(array $suggestions, array $variables) {

  // Ensure that a template is set in the info file.
  if (isset($this->pluginDefinition['template'])) {
    $template = $this->pluginDefinition['template'];
    $styles = $this
      ->getStylesFromVariables($variables);

    // Only set suggestions if styles have been set for the block.
    if ($styles) {
      foreach ($styles as $style) {
        if (!empty($style)) {
          $suggestions[] = $template;
          break;
        }
      }
    }
  }
  return $suggestions;
}