This project is not covered by Drupal’s security advisory policy.

This module has been replaced by the Plugin module.

Plugin selectors allow users to select plugins of a particular type and configure them using the plugins' configuration forms.

This module is a tool for other modules to build user interfaces. Using plugin selectors, your users can easily select and configure your plugins and you won't have to write any complex form API integration; the plugin selectors will do that for you.

Usage

In any form, do the following:


  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['plugin'] = $this->getPluginSelector($form_state)->buildSelectorForm([], $form_state);

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array $form, FormStateInterface $form_state) {
    $this->getPluginSelector($form_state)->validateSelectorForm([], $form_state);

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array $form, FormStateInterface $form_state) {
    $this->getPluginSelector($form_state)->submitSelectorForm([], $form_state);

    $plugin = $this->getPluginSelector($form_state)->getSelectedPlugin();

    return $form;
  }

  /**
   * Gets the plugin selector.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *
   * @return \Drupal\payment\Plugin\Payment\PluginSelector\PluginSelectorInterface
   */
  protected function getPluginSelector(FormStateInterface $form_state) {
    if (!$form_state->has('plugin_selector')) {
      $plugin_selector_id = 'plugin_selector_select_list';
      $mapper = new DefaultPluginDefinitionMapper();
      $plugin_selector = $this->pluginSelectorManager->createInstance($plugin_selector_id)
        ->setPluginManager($this->selectablePluginManager, $mapper)
        ->setRequired()
        ->setLabel($this->t('Select a plugin'));
      $form_state->set('plugin_selector', $plugin_selector);
    }

    return $form_state->get('plugin_selector');
  }
Supporting organizations: 

Project information

  • Created by xano on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases