webhooks-8.x-1.x-dev/modules/webhook/src/Form/MappingDeleteConfirmForm.php
modules/webhook/src/Form/MappingDeleteConfirmForm.php
<?php
declare(strict_types=1);
namespace Drupal\webhook\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
/**
* Mapping delete confirm form.
*/
final class MappingDeleteConfirmForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'webhook_mapping_delete_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion(): TranslatableMarkup {
return $this->t('Are you sure you want to do this?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl(): Url {
return new Url('system.admin_config');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$field_name = $this->getRouteMatch()->getParameter('field_name');
$webhook_type = $this->getRouteMatch()->getParameter('webhook_type');
$mapping = $this->configFactory()
->getEditable('webhook.mappings.' . $this->getRouteMatch()->getParameter('webhook_type'))
->get('mapping');
unset($mapping[$field_name]);
$this->configFactory()
->getEditable('webhook.mappings.' . $this->getRouteMatch()->getParameter('webhook_type'))
->set('mapping', $mapping)
->save();
$this->messenger()->addStatus($this->t('Mapping has been deleted.'));
$form_state->setRedirectUrl(new Url('webhook.webhook_type.field_mapping', [
'webhook_type' => $webhook_type,
]));
}
}
