PriceCategoryDeleteForm.php (2021B)
1 <?php 2 3 /** 4 * @file 5 * Location: src/Form/PriceCategoryDeleteForm.php 6 * 7 * Confirmation form for deleting a price category. 8 */ 9 10 namespace Drupal\taler_turnstile\Form; 11 12 use Drupal\Core\Entity\EntityConfirmFormBase; 13 use Drupal\Core\Form\FormStateInterface; 14 use Drupal\Core\Url; 15 use Drupal\taler_turnstile\TalerBackendErrorKind; 16 17 /** 18 * Builds the form to delete a price category. 19 */ 20 class PriceCategoryDeleteForm extends EntityConfirmFormBase { 21 22 /** 23 * {@inheritdoc} 24 */ 25 public function getQuestion() { 26 return $this->t('Are you sure you want to delete the price category %name?', [ 27 '%name' => $this->entity->label(), 28 ]); 29 } 30 31 /** 32 * {@inheritdoc} 33 */ 34 public function getCancelUrl() { 35 return new Url('entity.taler_turnstile_price_category.collection'); 36 } 37 38 /** 39 * {@inheritdoc} 40 */ 41 public function getConfirmText() { 42 return $this->t('Delete'); 43 } 44 45 /** 46 * {@inheritdoc} 47 */ 48 public function submitForm(array &$form, FormStateInterface $form_state) { 49 $this->entity->delete(); 50 51 $this->messenger()->addStatus($this->t('Price category %label has been deleted.', [ 52 '%label' => $this->entity->label(), 53 ])); 54 55 // postDelete() stashes the merchant-backend delete result on the 56 // entity instance. The local delete has already succeeded; if the 57 // template did NOT make it off the backend, warn the admin so 58 // they know to clean it up manually rather than discover stale 59 // templates later. 60 $sync = $this->entity->lastSyncResult; 61 if ($sync !== NULL && !$sync->isOk() 62 && $sync->kind !== TalerBackendErrorKind::NOT_CONFIGURED) { 63 $backend_url = (string) (\Drupal::config('taler_turnstile.settings')->get('payment_backend_url') ?? ''); 64 $this->messenger()->addWarning($this->t( 65 'Deleted locally, but failed to remove the matching template from the merchant backend: @err', 66 ['@err' => $sync->toUserMessage($backend_url)] 67 )); 68 } 69 70 $form_state->setRedirectUrl($this->getCancelUrl()); 71 } 72 73 }