You are here

public function ObjectOptionsFormBase::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

1 call to ObjectOptionsFormBase::submitForm()
ProductOptionsForm::submitForm in uc_attribute/src/Form/ProductOptionsForm.php
Form submission handler.
1 method overrides ObjectOptionsFormBase::submitForm()
ProductOptionsForm::submitForm in uc_attribute/src/Form/ProductOptionsForm.php
Form submission handler.

File

uc_attribute/src/Form/ObjectOptionsFormBase.php, line 206

Class

ObjectOptionsFormBase
Defines the class/product attributes options form.

Namespace

Drupal\uc_attribute\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue('attributes') as $aid => $attribute) {
    if (isset($attribute['default'])) {
      \Drupal::database()
        ->update($this->attributeTable)
        ->fields([
        'default_option' => $attribute['default'],
      ])
        ->condition($this->idField, $this->idValue)
        ->condition('aid', $aid)
        ->execute();
    }
    if (isset($attribute['options'])) {
      \Drupal::database()
        ->delete($this->optionTable)
        ->condition($this->idField, $this->idValue)
        ->condition('oid', array_keys($attribute['options']), 'IN')
        ->execute();
      foreach ($attribute['options'] as $oid => $option) {
        if ($option['select']) {
          unset($option['select']);
          $option[$this->idField] = $this->idValue;
          $option['oid'] = $oid;
          \Drupal::database()
            ->insert($this->optionTable)
            ->fields($option)
            ->execute();
        }
        else {
          $this
            ->optionRemoved($aid, $oid);
        }
      }
    }
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('The changes have been saved.'));
}