class Categories in Block field 8
Provides a 'categories' BlockFieldSection.
Plugin annotation
@BlockFieldSelection(
id = "categories",
label = @Translation("Categories"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\block_field\BlockFieldSelectionBase implements BlockFieldSelectionInterface, ConfigurableInterface
- class \Drupal\block_field\Plugin\block_field\BlockFieldSelection\Categories uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\block_field\BlockFieldSelectionBase implements BlockFieldSelectionInterface, ConfigurableInterface
Expanded class hierarchy of Categories
2 string references to 'Categories'
- block_field.yml in config/
schema/ block_field.yml - config/schema/block_field.yml
- Categories::buildConfigurationForm in src/
Plugin/ block_field/ BlockFieldSelection/ Categories.php - Form constructor.
File
- src/
Plugin/ block_field/ BlockFieldSelection/ Categories.php, line 18
Namespace
Drupal\block_field\Plugin\block_field\BlockFieldSelectionView source
class Categories extends BlockFieldSelectionBase {
use DependencySerializationTrait;
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'categories' => [],
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\block_field\BlockFieldManagerInterface $block_field_manager */
$block_field_manager = \Drupal::service('block_field.manager');
$categories = $block_field_manager
->getBlockCategories();
$options = [];
foreach ($categories as $category) {
$category = (string) $category;
$options[$category] = $category;
}
$form['categories'] = [
'#type' => 'details',
'#title' => $this
->t('Categories'),
'#description' => $this
->t('Please select available categories.'),
'#open' => empty($this
->getConfiguration()['categories']),
'#process' => [
[
$this,
'formProcessMergeParent',
],
],
];
$default_value = !empty($this
->getConfiguration()['categories']) ? $this
->getConfiguration()['categories'] : array_keys($options);
$form['categories']['categories'] = [
'#type' => 'checkboxes',
'#header' => [
'Category',
],
'#options' => $options,
'#js_select' => TRUE,
'#empty' => $this
->t('No categories are available.'),
'#required' => TRUE,
'#default_value' => array_combine($default_value, $default_value),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function getReferenceableBlockDefinitions() {
$block_field_manager = \Drupal::service('block_field.manager');
$definitions = $block_field_manager
->getBlockDefinitions();
if (!empty($this
->getConfiguration()['categories'])) {
$categories = array_filter($this
->getConfiguration()['categories']);
$definitions = array_filter($definitions, function ($definition, $key) use ($categories) {
return isset($categories[(string) $definition['category']]);
}, ARRAY_FILTER_USE_BOTH);
}
return $definitions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockFieldSelectionBase:: |
public | function | Move settings up a level for easier processing and storage. | |
BlockFieldSelectionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
BlockFieldSelectionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
BlockFieldSelectionBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
BlockFieldSelectionBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
BlockFieldSelectionBase:: |
public | function |
Constructs a new selection object. Overrides PluginBase:: |
|
Categories:: |
public | function |
Form constructor. Overrides BlockFieldSelectionBase:: |
|
Categories:: |
public | function |
Gets default configuration for this plugin. Overrides BlockFieldSelectionBase:: |
|
Categories:: |
public | function |
Returns filtered block definitions based on plugin settings. Overrides BlockFieldSelectionInterface:: |
|
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 | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
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. |