class WebhookDeleteConfirmForm in Acquia Content Hub 8.2
Confirmation form for webhook deletion.
@package Drupal\acquia_contenthub_publisher\Form\Webhook
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\acquia_contenthub_publisher\Form\Webhook\WebhookDeleteConfirmForm uses AcquiaContentHubUnregisterHelperTrait, SubscriptionManagerFormTrait
Expanded class hierarchy of WebhookDeleteConfirmForm
1 string reference to 'WebhookDeleteConfirmForm'
- acquia_contenthub_publisher.routing.yml in modules/
acquia_contenthub_publisher/ acquia_contenthub_publisher.routing.yml - modules/acquia_contenthub_publisher/acquia_contenthub_publisher.routing.yml
File
- modules/
acquia_contenthub_publisher/ src/ Form/ Webhook/ WebhookDeleteConfirmForm.php, line 21
Namespace
Drupal\acquia_contenthub_publisher\Form\WebhookView source
class WebhookDeleteConfirmForm extends FormBase {
use SubscriptionManagerFormTrait;
use AcquiaContentHubUnregisterHelperTrait;
/**
* The Acquia ContentHub Client object.
*
* @var \Acquia\ContentHubClient\ContentHubClient
*/
protected $client;
/**
* The Acquia ContentHub Unregister event.
*
* @var \Drupal\acquia_contenthub\Event\AcquiaContentHubUnregisterEvent
*/
protected $event;
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* The UUID of a webhook delete.
*
* @var string
*/
protected $uuid;
/**
* WebhookDeleteConfirmForm constructor.
*
* @param \Drupal\acquia_contenthub\Client\ClientFactory $client_factory
* ACH client factory.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* Symfony event dispatcher.
*/
public function __construct(ClientFactory $client_factory, EventDispatcherInterface $dispatcher) {
$this->client = $client_factory
->getClient();
$this->dispatcher = $dispatcher;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('acquia_contenthub.client.factory'), $container
->get('event_dispatcher'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $uuid = NULL) {
$this->uuid = $uuid;
$this->event = new AcquiaContentHubUnregisterEvent($this->uuid, '', TRUE);
$this->dispatcher
->dispatch(AcquiaContentHubEvents::ACH_UNREGISTER, $this->event);
$form['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#button_type' => 'primary',
'#name' => 'cancel',
'#weight' => 101,
];
$orphaned_filters = $this->event
->getOrphanedFilters();
if (!empty($orphaned_filters)) {
$form['filters'] = [
'#type' => 'details',
'#title' => $this
->t('With webhook deletion the following filters will be deleted as well:'),
'#open' => TRUE,
'#weight' => -1,
];
$form['filters']['orphaned_filters'] = [
'#type' => 'table',
'#title' => $this
->t('Filters'),
'#header' => [
'Filter name',
'Filter UUID',
],
'#rows' => $this
->formatOrphanedFiltersTable($orphaned_filters),
];
$form['actions']['delete_webhook_and_filters'] = [
'#type' => 'submit',
'#submit' => [
[
$this,
'deleteFilters',
],
[
$this,
'deleteWebhook',
],
],
'#value' => $this
->t('Delete webhook and filters'),
'#button_type' => 'primary',
'#weight' => 100,
'#limit_validation_errors' => [],
];
if ($this
->checkDiscoveryRoute()) {
$form['actions']['redirect'] = [
'#type' => 'link',
'#title' => $this
->t('Go to Discovery Interface'),
'#url' => Url::fromRoute('acquia_contenthub_curation.discovery'),
'#weight' => 99,
'#attributes' => [
'class' => [
'button',
],
],
];
}
return $form;
}
$this
->messenger()
->addStatus('Everything is in order, safe to proceed!');
$form['actions']['delete_webhook'] = [
'#type' => 'submit',
'#submit' => [
[
$this,
'deleteFilters',
],
[
$this,
'deleteWebhook',
],
],
'#value' => $this
->t('Delete webhook'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#name'] === 'cancel') {
$form_state
->setRedirect('acquia_contenthub.subscription_settings');
}
}
/**
* Delete orphaned and default filters from event.
*/
public function deleteFilters() : void {
foreach ($this->event
->getOrphanedFilters() as $filter_id) {
$response = $this->client
->deleteFilter($filter_id);
if (!$this
->isResponseSuccessful($response, $this
->t('delete'), $this
->t('filter'), $filter_id, $this
->messenger())) {
return;
}
}
$default_filter_response = $this->client
->deleteFilter($this->event
->getDefaultFilter());
$this
->isResponseSuccessful($default_filter_response, $this
->t('delete'), $this
->t('default filter'), $this->event
->getDefaultFilter(), $this
->messenger());
}
/**
* Delete webhook.
*
* @param array $form
* Form object.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state interface object.
*/
public function deleteWebhook(array &$form, FormStateInterface $form_state) : void {
$response = $this->client
->deleteWebhook($this->uuid);
if (!$this
->isResponseSuccessful($response, $this
->t('delete'), $this
->t('webhook'), $this->uuid, $this
->messenger())) {
return;
}
$this
->messenger()
->addStatus($this
->t('Webhook %uuid has been deleted successfully.', [
'%uuid' => $this->uuid,
]));
$form_state
->setRedirect('acquia_contenthub.subscription_settings');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'acquia_contenthub_webhook_delete_confirm_form';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaContentHubUnregisterHelperTrait:: |
public | function | Checks if Discovery Interface route exists. | |
AcquiaContentHubUnregisterHelperTrait:: |
protected | function | Format rows for render array. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
SubscriptionManagerFormTrait:: |
protected | function | Returns the success status of the response. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WebhookDeleteConfirmForm:: |
protected | property | The Acquia ContentHub Client object. | |
WebhookDeleteConfirmForm:: |
protected | property | The event dispatcher. | |
WebhookDeleteConfirmForm:: |
protected | property | The Acquia ContentHub Unregister event. | |
WebhookDeleteConfirmForm:: |
protected | property | The UUID of a webhook delete. | |
WebhookDeleteConfirmForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
WebhookDeleteConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
WebhookDeleteConfirmForm:: |
public | function | Delete orphaned and default filters from event. | |
WebhookDeleteConfirmForm:: |
public | function | Delete webhook. | |
WebhookDeleteConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
WebhookDeleteConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
WebhookDeleteConfirmForm:: |
public | function | WebhookDeleteConfirmForm constructor. |