You are here

public function AdvancedPluginSelectorBase::buildOneAvailablePlugin in Plugin 8.2

Builds the form elements for one plugin.

File

src/Plugin/Plugin/PluginSelector/AdvancedPluginSelectorBase.php, line 251

Class

AdvancedPluginSelectorBase
Provides a default base for most plugin selectors.

Namespace

Drupal\plugin\Plugin\Plugin\PluginSelector

Code

public function buildOneAvailablePlugin(array $element, FormStateInterface $form_state) {
  $plugin = reset($element['#available_plugins']);

  // Use the only available plugin if no other was configured before, or the
  // configured plugin is not available.
  if (is_null($this
    ->getSelectedPlugin()) || $this
    ->getSelectedPlugin()
    ->getPluginId() != $plugin
    ->getPluginId()) {
    $this
      ->setSelectedPlugin($plugin);
  }
  $element['select']['message'] = [
    '#title' => $this
      ->getLabel(),
    '#type' => 'item',
  ];
  $element['select']['container'] = [
    '#type' => 'container',
  ];
  $element['select']['container']['plugin_id'] = [
    '#type' => 'value',
    '#value' => $this
      ->getSelectedPlugin()
      ->getPluginId(),
  ];
  $element['plugin_form'] = $this
    ->buildPluginForm($form_state);
  return $element;
}