You are here

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

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\PluginSelector
View 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

Namesort descending Modifiers Type Description Overrides
AdvancedPluginSelectorBase::ajaxRebuildForm public static function Implements form AJAX callback.
AdvancedPluginSelectorBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
AdvancedPluginSelectorBase::buildMultipleAvailablePlugins public function Builds the form elements for multiple plugins.
AdvancedPluginSelectorBase::buildNoAvailablePlugins public function Builds the form elements for when there are no available plugins.
AdvancedPluginSelectorBase::buildOneAvailablePlugin public function Builds the form elements for one plugin.
AdvancedPluginSelectorBase::buildPluginForm protected function Builds the plugin configuration form elements.
AdvancedPluginSelectorBase::create public static function Creates an instance of the plugin. Overrides PluginSelectorBase::create
AdvancedPluginSelectorBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides PluginSelectorBase::defaultConfiguration
AdvancedPluginSelectorBase::getPluginSelector protected static function Gets a plugin selector from the form state.
AdvancedPluginSelectorBase::getSelectorVisibilityForSingleAvailability public function Gets whether or not to show the selection elements for single plugins.
AdvancedPluginSelectorBase::processBuildSelectorForm public static function Implements a Form API #process callback.
AdvancedPluginSelectorBase::rebuildForm public static function Implements form API's #submit.
AdvancedPluginSelectorBase::setPluginSelector protected static function Stores a plugin selector in the form state.
AdvancedPluginSelectorBase::setSelectorVisibilityForSingleAvailability public function Toggles whether or not to show the selection elements for single plugins.
AdvancedPluginSelectorBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
AdvancedPluginSelectorBase::submitSelectorForm public function Submits the selector form. Overrides PluginSelectorInterface::submitSelectorForm
AdvancedPluginSelectorBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
AdvancedPluginSelectorBase::validateSelectorForm public function Validates the selector form. Overrides PluginSelectorInterface::validateSelectorForm
AdvancedPluginSelectorBase::__construct public function Constructs a new class instance. Overrides PluginSelectorBase::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginSelectorBase::$defaultPluginResolver protected property The default plugin resolver.
PluginSelectorBase::$previouslySelectedPlugins protected property The previously selected plugins.
PluginSelectorBase::$selectablePluginDiscovery protected property The plugin discovery of selectable plugins.
PluginSelectorBase::$selectablePluginFactory protected property The selectable plugin factory.
PluginSelectorBase::$selectablePluginType protected property The plugin type of which to select plugins.
PluginSelectorBase::$selectedPlugin protected property The selected plugin.
PluginSelectorBase::calculateDependencies public function
PluginSelectorBase::getCollectPluginConfiguration public function Gets whether a plugin's configuration must be collected. Overrides PluginSelectorInterface::getCollectPluginConfiguration
PluginSelectorBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
PluginSelectorBase::getDescription public function Gets the human-readable description. Overrides PluginSelectorInterface::getDescription
PluginSelectorBase::getKeepPreviouslySelectedPlugins public function Gets whether previously selected plugins must be kept. Overrides PluginSelectorInterface::getKeepPreviouslySelectedPlugins
PluginSelectorBase::getLabel public function Gets the human-readable label. Overrides PluginSelectorInterface::getLabel
PluginSelectorBase::getPreviouslySelectedPlugins public function Gets previously selected plugins. Overrides PluginSelectorInterface::getPreviouslySelectedPlugins
PluginSelectorBase::getSelectedPlugin public function Gets the selected plugin. Overrides PluginSelectorInterface::getSelectedPlugin
PluginSelectorBase::isRequired public function Returns whether a plugin must be selected. Overrides PluginSelectorInterface::isRequired
PluginSelectorBase::resetSelectedPlugin public function Resets the selected plugin. Overrides PluginSelectorInterface::resetSelectedPlugin
PluginSelectorBase::setCollectPluginConfiguration public function Sets whether a plugin's configuration must be collected. Overrides PluginSelectorInterface::setCollectPluginConfiguration
PluginSelectorBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
PluginSelectorBase::setDescription public function Sets the human-readable description. Overrides PluginSelectorInterface::setDescription
PluginSelectorBase::setKeepPreviouslySelectedPlugins public function Sets whether previously selected plugins must be kept. Overrides PluginSelectorInterface::setKeepPreviouslySelectedPlugins
PluginSelectorBase::setLabel public function Sets the human-readable label. Overrides PluginSelectorInterface::setLabel
PluginSelectorBase::setPreviouslySelectedPlugins public function Sets previously selected plugins. Overrides PluginSelectorInterface::setPreviouslySelectedPlugins
PluginSelectorBase::setRequired public function Sets whether a plugin must be selected. Overrides PluginSelectorInterface::setRequired
PluginSelectorBase::setSelectablePluginDiscovery public function Overrides the plugin type's discovery. Overrides PluginSelectorInterface::setSelectablePluginDiscovery
PluginSelectorBase::setSelectablePluginFactory public function Overrides the plugin type's factory. Overrides PluginSelectorInterface::setSelectablePluginFactory
PluginSelectorBase::setSelectablePluginType public function Sets the selectable plugin type. Overrides PluginSelectorInterface::setSelectablePluginType
PluginSelectorBase::setSelectedPlugin public function Sets the selected plugin. Overrides PluginSelectorInterface::setSelectedPlugin
PluginSelectorBase::validateSelectablePluginType protected function Validates the selectable plugin type.
Radios::buildSelector protected function Builds the form elements for the actual plugin selector. Overrides AdvancedPluginSelectorBase::buildSelector
Radios::buildSelectorForm public function Builds the selector form. Overrides AdvancedPluginSelectorBase::buildSelectorForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.