You are here

public function CommerceCurrencyResolverMapping::submitForm in Commerce Currency Resolver 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides ConfigFormBase::submitForm

File

src/Form/CommerceCurrencyResolverMapping.php, line 209

Class

CommerceCurrencyResolverMapping
Class CommerceCurrencyResolverMapping.

Namespace

Drupal\commerce_currency_resolver\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('commerce_currency_resolver.currency_mapping');

  // Get matrix logic value.
  $logic = $form_state
    ->getValue('logic');

  // Process results in some cases.
  // We want to have same array in any type of currency matrix.
  if ($logic === 'currency') {
    $raw_data = $form_state
      ->getValue('matrix');
    $matrix = [];
    foreach ($raw_data as $currency => $list) {
      $countries = explode(',', $list);
      foreach ($countries as $country) {
        $matrix[$country] = $currency;
      }
    }
  }
  else {
    $matrix = $form_state
      ->getValue('matrix');
  }

  // Set values.
  $config
    ->set('domicile_currency', $form_state
    ->getValue('domicile_currency'))
    ->set('logic', $logic)
    ->set('matrix', $matrix)
    ->save();
  parent::submitForm($form, $form_state);
}