You are here

public function AttributeDeleteForm::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/AttributeDeleteForm.php, line 69

Class

AttributeDeleteForm
Defines the attribute delete form.

Namespace

Drupal\uc_attribute\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $options = array_keys($this->attribute->options);
  if ($options) {
    \Drupal::database()
      ->delete('uc_class_attribute_options')
      ->condition('oid', $options, 'IN')
      ->execute();
    \Drupal::database()
      ->delete('uc_product_options')
      ->condition('oid', $options, 'IN')
      ->execute();
  }
  if ($nodes = \Drupal::database()
    ->query("SELECT nid FROM {uc_product_attributes} WHERE aid = :aid", [
    ':aid' => $this->attribute->aid,
  ])
    ->fetchCol()) {
    \Drupal::database()
      ->delete('uc_product_adjustments')
      ->condition('nid', $nodes, 'IN')
      ->execute();
  }
  \Drupal::database()
    ->delete('uc_class_attributes')
    ->condition('aid', $this->attribute->aid)
    ->execute();
  \Drupal::database()
    ->delete('uc_product_attributes')
    ->condition('aid', $this->attribute->aid)
    ->execute();
  \Drupal::database()
    ->delete('uc_attribute_options')
    ->condition('aid', $this->attribute->aid)
    ->execute();
  \Drupal::database()
    ->delete('uc_attributes')
    ->condition('aid', $this->attribute->aid)
    ->execute();
  $this
    ->messenger()
    ->addMessage($this
    ->t('Product attribute deleted.'));
  $form_state
    ->setRedirect('uc_attribute.overview');
}