PackageDeleteForm.php in Ubercart 8.4
File
shipping/uc_fulfillment/src/Form/PackageDeleteForm.php
View source
<?php
namespace Drupal\uc_fulfillment\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\uc_fulfillment\PackageInterface;
use Drupal\uc_order\OrderInterface;
class PackageDeleteForm extends ConfirmFormBase {
protected $order_id;
protected $package;
public function getFormId() {
return 'uc_fulfillment_package_delete_confirm';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete this package?');
}
public function getDescription() {
return $this
->t('The products it contains will be available for repackaging.');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function getCancelUrl() {
return Url::fromRoute('uc_fulfillment.packages', [
'uc_order' => $this->order_id,
]);
}
public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, PackageInterface $uc_package = NULL) {
$this->order_id = $uc_order
->id();
$this->package = $uc_package;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->package
->delete();
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}