ProductFeatureDeleteForm.php in Ubercart 8.4
File
uc_product/src/Form/ProductFeatureDeleteForm.php
View source
<?php
namespace Drupal\uc_product\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
class ProductFeatureDeleteForm extends ConfirmFormBase {
protected $node;
protected $featureId;
protected $feature;
public function getQuestion() {
return $this
->t('Are you sure you want to delete this %feature?', [
'%feature' => uc_product_feature_data($this->featureId, 'title'),
]);
}
public function getDescription() {
return $this->feature['description'];
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return Url::fromRoute('uc_product.features', [
'node' => $this->node
->id(),
]);
}
public function getFormId() {
return 'uc_product_feature_confirm_delete';
}
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL, $fid = NULL, $pfid = NULL) {
$this->node = $node;
$this->featureId = $fid;
$this->feature = uc_product_feature_load($pfid);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
uc_product_feature_delete($this->feature['pfid']);
$this
->messenger()
->addMessage($this
->t('The product feature has been deleted.'));
$form_state
->setRedirect('uc_product.features', [
'node' => $this->node
->id(),
]);
}
}