abstract class PluginSelectorBase in Plugin 8.2
Provides a base plugin selector.
Plugins extending this class should provide a configuration schema that extends plugin_selector.plugin_configuration.plugin_selector.plugin_selector_base.
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\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PluginSelectorBase
1 file declares its use of PluginSelectorBase
- PluginSelectorBaseTest.php in tests/src/ Unit/ Plugin/ Plugin/ PluginSelector/ PluginSelectorBaseTest.php 
File
- src/Plugin/ Plugin/ PluginSelector/ PluginSelectorBase.php, line 23 
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorView source
abstract class PluginSelectorBase extends PluginBase implements PluginSelectorInterface, ContainerFactoryPluginInterface {
  /**
   * The default plugin resolver.
   *
   * @var \Drupal\plugin\DefaultPluginResolver\DefaultPluginResolverInterface
   */
  protected $defaultPluginResolver;
  /**
   * The previously selected plugins.
   *
   * @var \Drupal\Component\Plugin\PluginInspectionInterface[]
   */
  protected $previouslySelectedPlugins = [];
  /**
   * The plugin discovery of selectable plugins.
   *
   * @var \Drupal\plugin\PluginDiscovery\TypedDiscoveryInterface
   */
  protected $selectablePluginDiscovery;
  /**
   * The selectable plugin factory.
   *
   * @var \Drupal\Component\Plugin\Factory\FactoryInterface
   */
  protected $selectablePluginFactory;
  /**
   * The plugin type of which to select plugins.
   *
   * @var \Drupal\plugin\PluginType\PluginTypeInterface
   */
  protected $selectablePluginType;
  /**
   * The selected plugin.
   *
   * @var \Drupal\Component\Plugin\PluginInspectionInterface
   */
  protected $selectedPlugin;
  /**
   * Constructs a new instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\plugin\DefaultPluginResolver\DefaultPluginResolverInterface $default_plugin_resolver
   *   The default plugin resolver.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, DefaultPluginResolverInterface $default_plugin_resolver) {
    $configuration += $this
      ->defaultConfiguration();
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->defaultPluginResolver = $default_plugin_resolver;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.default_plugin_resolver'));
  }
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [];
  }
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'description' => NULL,
      'label' => NULL,
      'required' => FALSE,
      'collect_plugin_configuration' => TRUE,
      'keep_previously_selected_plugins' => TRUE,
    ];
  }
  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }
  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function setLabel($label) {
    $this->configuration['label'] = $label;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this->configuration['label'];
  }
  /**
   * {@inheritdoc}
   */
  public function setDescription($description) {
    $this->configuration['description'] = $description;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->configuration['description'];
  }
  /**
   * {@inheritdoc}
   */
  public function setRequired($required = TRUE) {
    $this->configuration['required'] = $required;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function isRequired() {
    return $this->configuration['required'];
  }
  /**
   * {@inheritdoc}
   */
  public function setCollectPluginConfiguration($collect = TRUE) {
    $this->configuration['collect_plugin_configuration'] = $collect;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getCollectPluginConfiguration() {
    return $this->configuration['collect_plugin_configuration'];
  }
  /**
   * {@inheritdoc}
   */
  public function setKeepPreviouslySelectedPlugins($keep = TRUE) {
    $this->configuration['keep_previously_selected_plugins'] = $keep;
    if ($keep === FALSE) {
      $this
        ->setPreviouslySelectedPlugins([]);
    }
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getKeepPreviouslySelectedPlugins() {
    return $this->configuration['keep_previously_selected_plugins'];
  }
  /**
   * {@inheritdoc}
   */
  public function setPreviouslySelectedPlugins(array $plugins) {
    $this->previouslySelectedPlugins = $plugins;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getPreviouslySelectedPlugins() {
    return $this->previouslySelectedPlugins;
  }
  /**
   * {@inheritdoc}
   */
  public function getSelectedPlugin() {
    return $this->selectedPlugin;
  }
  /**
   * {@inheritdoc}
   */
  public function setSelectedPlugin(PluginInspectionInterface $plugin) {
    $this
      ->validateSelectablePluginType();
    $this->selectedPlugin = $plugin;
    if ($this
      ->getKeepPreviouslySelectedPlugins()) {
      $this->previouslySelectedPlugins[$plugin
        ->getPluginId()] = $plugin;
    }
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function resetSelectedPlugin() {
    $this->selectedPlugin = NULL;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function setSelectablePluginType(PluginTypeInterface $plugin_type) {
    $this->selectablePluginDiscovery = new TypedDefinitionEnsuringPluginDiscoveryDecorator($plugin_type);
    $this->selectablePluginFactory = $plugin_type
      ->getPluginManager();
    $this->selectablePluginType = $plugin_type;
    $default_plugin = $this->defaultPluginResolver
      ->createDefaultPluginInstance($plugin_type);
    if ($default_plugin) {
      $this
        ->setSelectedPlugin($default_plugin);
    }
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function setSelectablePluginDiscovery(DiscoveryInterface $plugin_discovery) {
    $this
      ->validateSelectablePluginType();
    $this->selectablePluginDiscovery = new TypedDefinitionEnsuringPluginDiscoveryDecorator($this->selectablePluginType, $plugin_discovery);
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function setSelectablePluginFactory(FactoryInterface $plugin_factory) {
    $this
      ->validateSelectablePluginType();
    $this->selectablePluginFactory = $plugin_factory;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function buildSelectorForm(array $form, FormStateInterface $form_state) {
    $this
      ->validateSelectablePluginType();
    return [];
  }
  /**
   * Validates the selectable plugin type.
   *
   * @throw \RuntimeException
   */
  protected function validateSelectablePluginType() {
    if (!$this->selectablePluginType) {
      throw new \RuntimeException('A plugin type must be set through static::setSelectablePluginType() first.');
    }
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 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 | Builds the selector form. Overrides PluginSelectorInterface:: | 1 | 
| PluginSelectorBase:: | public | function | ||
| PluginSelectorBase:: | public static | function | Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: | 1 | 
| PluginSelectorBase:: | public | function | Gets default configuration for this plugin. Overrides ConfigurableInterface:: | 1 | 
| 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. | |
| PluginSelectorBase:: | public | function | Constructs a new instance. Overrides PluginBase:: | 1 | 
| PluginSelectorInterface:: | public | function | Submits the selector form. | 1 | 
| PluginSelectorInterface:: | public | function | Validates the selector form. | 1 | 
| 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. | 
