You are here

public static function PluginConfiguration::submitPluginConfiguration in Commerce Core 8.2

Submits the plugin configuration.

Parameters

array $element: An associative array containing the properties of the element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Element/PluginConfiguration.php, line 135

Class

PluginConfiguration
Provides a form element for configuring plugins.

Namespace

Drupal\commerce\Element

Code

public static function submitPluginConfiguration(array &$element, FormStateInterface $form_state) {
  if (!empty($element['#plugin_id'])) {

    /** @var \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager */
    $plugin_manager = \Drupal::service('plugin.manager.' . $element['#plugin_type']);
    $plugin = $plugin_manager
      ->createInstance($element['#plugin_id'], $element['#default_value']);
    $plugin
      ->submitConfigurationForm($element['form'], $form_state);
    $form_state
      ->setValueForElement($element, $plugin
      ->getConfiguration());
  }
}