class BlockStyle in Block Style Plugins 8
Same name in this branch
- 8 src/Annotation/BlockStyle.php \Drupal\block_style_plugins\Annotation\BlockStyle
- 8 src/Plugin/BlockStyle.php \Drupal\block_style_plugins\Plugin\BlockStyle
Same name and namespace in other branches
- 8.2 src/Plugin/BlockStyle.php \Drupal\block_style_plugins\Plugin\BlockStyle
Provides a default class for block styles declared by yaml.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\block_style_plugins\Plugin\BlockStyleBase implements BlockStyleInterface, ContainerFactoryPluginInterface
- class \Drupal\block_style_plugins\Plugin\BlockStyle
- class \Drupal\block_style_plugins\Plugin\BlockStyleBase implements BlockStyleInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BlockStyle
1 file declares its use of BlockStyle
- BlockStyleTest.php in tests/
src/ Unit/ Plugin/ BlockStyleTest.php
File
- src/
Plugin/ BlockStyle.php, line 10
Namespace
Drupal\block_style_plugins\PluginView source
class BlockStyle extends BlockStyleBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$defaults = [];
if (isset($this->pluginDefinition['form'])) {
foreach ($this->pluginDefinition['form'] as $field => $setting) {
if (isset($setting['#default_value'])) {
$defaults[$field] = $setting['#default_value'];
}
}
}
return $defaults;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$elements = [];
// Get form fields from Yaml.
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;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockStyle:: |
public | function |
Form constructor. Overrides BlockStyleBase:: |
|
BlockStyle:: |
public | function |
Gets default configuration for this plugin. Overrides BlockStyleBase:: |
|
BlockStyle:: |
public | function |
Add theme suggestions for the block. Overrides BlockStyleBase:: |
|
BlockStyleBase:: |
protected | property | Bundle type for 'Block Content' blocks. | |
BlockStyleBase:: |
protected | property | Plugin instance for the Block being configured. | |
BlockStyleBase:: |
protected | property | Instance of the Entity Repository service. | |
BlockStyleBase:: |
protected | property | Instance of the Entity Type Manager service. | |
BlockStyleBase:: |
protected | property |
Plugin ID for the Block being configured. Overrides PluginBase:: |
|
BlockStyleBase:: |
protected | property | Style settings for the block styles. | |
BlockStyleBase:: |
protected | function | Determine if a plugin ID matches a Base ID in a list of include/exclude. | |
BlockStyleBase:: |
public | function |
Builds and returns the renderable array for this block style plugin. Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
BlockStyleBase:: |
public | function | Gets default style configuration for this plugin. | |
BlockStyleBase:: |
public | function |
Exclude styles from appearing on a block. Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public | function |
Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public | function | Returns an array of field elements. | |
BlockStyleBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
BlockStyleBase:: |
public | function | Gets this plugin's style configuration. | |
BlockStyleBase:: |
protected | function | Get styles for a block set in a preprocess $variables array. | |
BlockStyleBase:: |
public | function |
Only show styles on specific blocks. Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public | function |
Returns the configuration form elements specific to a block configuration. Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public | function | Set the block content bundle type. | |
BlockStyleBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
BlockStyleBase:: |
public | function | Sets the style configuration for this plugin instance. | |
BlockStyleBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
BlockStyleBase:: |
public | function |
Overrides BlockStyleInterface:: |
|
BlockStyleBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
BlockStyleBase:: |
public | function | Adds block style specific validation handling for the block form. | |
BlockStyleBase:: |
public | function |
Construct method for BlockStyleBase. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |