BlockStyle.php in Block Style Plugins 8.2
File
src/Plugin/BlockStyle.php
View source
<?php
namespace Drupal\block_style_plugins\Plugin;
use Drupal\Core\Form\FormStateInterface;
class BlockStyle extends BlockStyleBase {
public function defaultConfiguration() {
$defaults = parent::defaultConfiguration();
if (isset($this->pluginDefinition['form'])) {
foreach ($this->pluginDefinition['form'] as $field => $setting) {
if (isset($setting['#default_value'])) {
$defaults[$field] = $setting['#default_value'];
}
}
}
return $defaults;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$elements = parent::buildConfigurationForm($form, $form_state);
foreach ($this->pluginDefinition['form'] as $field => $setting) {
$element = [];
foreach ($setting as $property_key => $property) {
$element[$property_key] = $property;
}
if (isset($this->configuration[$field])) {
$element['#default_value'] = $this->configuration[$field];
}
$elements[$field] = $element;
}
return $elements;
}
public function themeSuggestion(array $suggestions, array $variables) {
if (isset($this->pluginDefinition['template'])) {
$template = $this->pluginDefinition['template'];
$styles = $this
->getStylesFromVariables($variables);
if ($styles) {
foreach ($styles as $style) {
if (!empty($style)) {
$suggestions[] = $template;
break;
}
}
}
}
return $suggestions;
}
}
Classes
Name |
Description |
BlockStyle |
Provides a default class for block styles declared by yaml. |