class SelectList in Plugin 8.2
Provides a plugin selector using a <select> element.
Plugin annotation
@PluginSelector(
id = "plugin_select_list",
label = @Translation("Drop-down selection list")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorBase implements ContainerFactoryPluginInterface, PluginSelectorInterface
- class \Drupal\plugin\Plugin\Plugin\PluginSelector\AdvancedPluginSelectorBase implements ContainerFactoryPluginInterface, PluginFormInterface
- class \Drupal\plugin\Plugin\Plugin\PluginSelector\SelectList uses PluginHierarchyTrait
- class \Drupal\plugin\Plugin\Plugin\PluginSelector\AdvancedPluginSelectorBase implements ContainerFactoryPluginInterface, PluginFormInterface
- class \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorBase implements ContainerFactoryPluginInterface, PluginSelectorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SelectList
1 file declares its use of SelectList
- SelectListTest.php in tests/
src/ Unit/ Plugin/ Plugin/ PluginSelector/ SelectListTest.php
File
- src/
Plugin/ Plugin/ PluginSelector/ SelectList.php, line 17
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorView source
class SelectList extends AdvancedPluginSelectorBase {
use PluginHierarchyTrait;
/**
* {@inheritdoc}
*/
protected function buildSelector(array $root_element, FormStateInterface $form_state, array $plugins) {
$element = parent::buildSelector($root_element, $form_state, $plugins);
/** @var \Drupal\Component\Plugin\PluginInspectionInterface[] $plugins */
$element['container']['plugin_id'] = [
'#ajax' => [
'callback' => [
get_class(),
'ajaxRebuildForm',
],
'effect' => 'fade',
'event' => 'change',
'trigger_as' => [
'name' => $element['container']['change']['#name'],
],
],
'#default_value' => $this
->getSelectedPlugin() ? $this
->getSelectedPlugin()
->getPluginId() : NULL,
'#empty_value' => '',
'#options' => $this
->buildOptionsLevel($this
->buildPluginHierarchy($this->selectablePluginDiscovery)),
'#required' => $this
->isRequired(),
'#title' => $this
->getLabel(),
'#description' => $this
->getDescription(),
'#type' => 'select',
];
return $element;
}
/**
* Helper function for self::options().
*
* @param array $hierarchy
* A plugin ID hierarchy as returned by self::hierarchy().
* @param integer $depth
* The depth of $hierarchy's top-level items as seen from the original
* hierarchy's root (this function is recursive), starting with 0.
*
* @return string[]
* Keys are plugin IDs.
*/
protected function buildOptionsLevel(array $hierarchy, $depth = 0) {
$plugin_definitions = $this->selectablePluginDiscovery
->getDefinitions();
$options = [];
$prefix = $depth ? str_repeat('-', $depth) . ' ' : '';
foreach ($hierarchy as $plugin_id => $child_plugin_ids) {
$plugin_definition = $plugin_definitions[$plugin_id];
$label = $plugin_definition instanceof PluginLabelDefinitionInterface ? $plugin_definition
->getLabel() : $plugin_definition
->getId();
$options[$plugin_id] = $prefix . $label;
$options += $this
->buildOptionsLevel($child_plugin_ids, $depth + 1);
}
return $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdvancedPluginSelectorBase:: |
public static | function | Implements form AJAX callback. | |
AdvancedPluginSelectorBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
AdvancedPluginSelectorBase:: |
public | function | Builds the form elements for multiple plugins. | |
AdvancedPluginSelectorBase:: |
public | function | Builds the form elements for when there are no available plugins. | |
AdvancedPluginSelectorBase:: |
public | function | Builds the form elements for one plugin. | |
AdvancedPluginSelectorBase:: |
protected | function | Builds the plugin configuration form elements. | |
AdvancedPluginSelectorBase:: |
public | function |
Builds the selector form. Overrides PluginSelectorBase:: |
1 |
AdvancedPluginSelectorBase:: |
public static | function |
Creates an instance of the plugin. Overrides PluginSelectorBase:: |
|
AdvancedPluginSelectorBase:: |
public | function |
Gets default configuration for this plugin. Overrides PluginSelectorBase:: |
|
AdvancedPluginSelectorBase:: |
protected static | function | Gets a plugin selector from the form state. | |
AdvancedPluginSelectorBase:: |
public | function | Gets whether or not to show the selection elements for single plugins. | |
AdvancedPluginSelectorBase:: |
public static | function | Implements a Form API #process callback. | |
AdvancedPluginSelectorBase:: |
public static | function | Implements form API's #submit. | |
AdvancedPluginSelectorBase:: |
protected static | function | Stores a plugin selector in the form state. | |
AdvancedPluginSelectorBase:: |
public | function | Toggles whether or not to show the selection elements for single plugins. | |
AdvancedPluginSelectorBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
AdvancedPluginSelectorBase:: |
public | function |
Submits the selector form. Overrides PluginSelectorInterface:: |
|
AdvancedPluginSelectorBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
AdvancedPluginSelectorBase:: |
public | function |
Validates the selector form. Overrides PluginSelectorInterface:: |
|
AdvancedPluginSelectorBase:: |
public | function |
Constructs a new class instance. Overrides PluginSelectorBase:: |
|
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:: |
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. | |
PluginHierarchyTrait:: |
protected | function | Returns a hierarchical plugin representation. | |
PluginHierarchyTrait:: |
protected | function | Helper function for self::hierarchy(). | |
PluginSelectorBase:: |
protected | property | The default plugin resolver. | |
PluginSelectorBase:: |
protected | property | The previously selected plugins. | |
PluginSelectorBase:: |
protected | property | The plugin discovery of selectable plugins. | |
PluginSelectorBase:: |
protected | property | The selectable plugin factory. | |
PluginSelectorBase:: |
protected | property | The plugin type of which to select plugins. | |
PluginSelectorBase:: |
protected | property | The selected plugin. | |
PluginSelectorBase:: |
public | function | ||
PluginSelectorBase:: |
public | function |
Gets whether a plugin's configuration must be collected. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets the human-readable description. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets whether previously selected plugins must be kept. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets the human-readable label. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets previously selected plugins. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Gets the selected plugin. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Returns whether a plugin must be selected. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Resets the selected plugin. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets whether a plugin's configuration must be collected. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets the human-readable description. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets whether previously selected plugins must be kept. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets the human-readable label. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets previously selected plugins. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets whether a plugin must be selected. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Overrides the plugin type's discovery. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Overrides the plugin type's factory. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets the selectable plugin type. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
public | function |
Sets the selected plugin. Overrides PluginSelectorInterface:: |
|
PluginSelectorBase:: |
protected | function | Validates the selectable plugin type. | |
SelectList:: |
protected | function | Helper function for self::options(). | |
SelectList:: |
protected | function |
Builds the form elements for the actual plugin selector. Overrides AdvancedPluginSelectorBase:: |
|
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. |