class Radios in Plugin 8.2
Provides a plugin selector using a radio buttons.
Plugin annotation
@PluginSelector(
id = "plugin_radios",
label = @Translation("Radio buttons")
)
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\Radios
- 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 Radios
1 file declares its use of Radios
- RadiosTest.php in tests/
src/ Unit/ Plugin/ Plugin/ PluginSelector/ RadiosTest.php
File
- src/
Plugin/ Plugin/ PluginSelector/ Radios.php, line 16
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorView source
class Radios extends AdvancedPluginSelectorBase {
/**
* {@inheritdoc}
*/
public function buildSelectorForm(array $form, FormStateInterface $form_state) {
$form = parent::buildSelectorForm($form, $form_state);
$form['clear'] = [
'#markup' => '<div style="clear: both;"></div>',
];
return $form;
}
/**
* {@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 */
$plugin_options = [];
foreach ($plugins as $plugin) {
$plugin_definition = $this->selectablePluginType
->ensureTypedPluginDefinition($plugin
->getPluginDefinition());
$plugin_options[$plugin
->getPluginId()] = $plugin_definition instanceof PluginLabelDefinitionInterface ? $plugin_definition
->getLabel() : $plugin_definition
->getId();
}
natcasesort($plugin_options);
$element['container']['plugin_id'] = [
'#ajax' => [
'callback' => [
get_class(),
'ajaxRebuildForm',
],
'effect' => 'fade',
'event' => 'change',
'progress' => 'none',
'trigger_as' => [
'name' => $element['container']['change']['#name'],
],
],
'#attached' => [
'library' => [
'plugin/plugin_selector.plugin_radios',
],
],
'#default_value' => $this
->getSelectedPlugin() ? $this
->getSelectedPlugin()
->getPluginId() : NULL,
'#empty_value' => 'select',
'#options' => $plugin_options,
'#required' => $this
->isRequired(),
'#title' => $this
->getlabel(),
'#description' => $this
->getDescription(),
'#type' => 'radios',
];
return $element;
}
}
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 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. | |
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. | |
Radios:: |
protected | function |
Builds the form elements for the actual plugin selector. Overrides AdvancedPluginSelectorBase:: |
|
Radios:: |
public | function |
Builds the selector form. 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. |