You are here

public function OptionEditForm::submitForm in Ubercart 8.4

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 FormInterface::submitForm

File

uc_attribute/src/Form/OptionEditForm.php, line 36

Class

OptionEditForm
Defines the attribute option edit form.

Namespace

Drupal\uc_attribute\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Remove Form API elements from $form_state.
  $form_state
    ->cleanValues();
  $oid = $form_state
    ->getValue('oid');
  \Drupal::database()
    ->merge('uc_attribute_options')
    ->key([
    'aid' => $form_state
      ->getValue('aid'),
    'oid' => $oid,
  ])
    ->fields($form_state
    ->getValues())
    ->execute();
  $aid = $form_state
    ->getValue('aid');
  $option_name = $form_state
    ->getValue('name');
  $edit_option_link = Link::createFromRoute($this
    ->t('Edit option'), 'uc_attribute.option_edit', [
    'aid' => $aid,
    'oid' => $oid,
  ])
    ->toString();
  $this
    ->messenger()
    ->addMessage($this
    ->t('Updated option %option.', [
    '%option' => $option_name,
  ]));
  $this
    ->logger('uc_attribute')
    ->notice('Updated option %option.', [
    '%option' => $option_name,
    'link' => $edit_option_link,
  ]);
  $form_state
    ->setRedirect('uc_attribute.options', [
    'aid' => $aid,
  ]);
}