OptionDeleteForm.php in Ubercart 8.4
File
uc_attribute/src/Form/OptionDeleteForm.php
View source
<?php
namespace Drupal\uc_attribute\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class OptionDeleteForm extends ConfirmFormBase {
protected $option;
public function getQuestion() {
return $this
->t('Are you sure you want to delete the option %name?', [
'%name' => $this->option->name,
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return Url::fromRoute('uc_attribute.options', [
'aid' => $this->option->aid,
]);
}
public function getFormId() {
return 'uc_attribute_option_delete_form';
}
public function buildForm(array $form, FormStateInterface $form_state, $aid = NULL, $oid = NULL) {
$this->option = uc_attribute_option_load($oid);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$match = 'i:' . $this->option->aid . ';s:' . strlen($this->option->oid) . ':"' . $this->option->oid . '";';
\Drupal::database()
->delete('uc_product_adjustments')
->condition('combination', '%' . \Drupal::database()
->escapeLike($match) . '%', 'LIKE')
->execute();
$select = \Drupal::database()
->select('uc_attribute_options', 'ao')
->where('{uc_class_attribute_options}.oid = ao.oid')
->condition('ao.oid', $this->option->oid);
$select
->addExpression('1');
\Drupal::database()
->delete('uc_class_attribute_options')
->condition('', $select, 'EXISTS')
->execute();
$select = \Drupal::database()
->select('uc_attribute_options', 'ao')
->where('{uc_product_options}.oid = ao.oid')
->condition('ao.oid', $this->option->oid);
$select
->addExpression('1');
\Drupal::database()
->delete('uc_product_options')
->condition('', $select, 'EXISTS')
->execute();
\Drupal::database()
->delete('uc_attribute_options')
->condition('oid', $this->option->oid)
->execute();
$form_state
->setRedirect('uc_attribute.options', [
'aid' => $this->option->aid,
]);
}
}