You are here

protected function SelectList::buildSelector in Plugin 8.2

Builds the form elements for the actual plugin selector.

Parameters

array $root_element: The plugin's root element.

\Drupal\Core\Form\FormStateInterface $form_state: The form's state.

\Drupal\Component\Plugin\PluginInspectionInterface[] $plugins: The available plugins.

Return value

array The selector's form elements.

Overrides AdvancedPluginSelectorBase::buildSelector

File

src/Plugin/Plugin/PluginSelector/SelectList.php, line 24

Class

SelectList
Provides a plugin selector using a <select> element.

Namespace

Drupal\plugin\Plugin\Plugin\PluginSelector

Code

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;
}