class ContentHubDeleteClientConfirmForm in Acquia Content Hub 8.2
Class ContentHubDeleteClientConfirmForm.
Defines a confirmation form to confirm deletion of Acquia Content Hub Client.
@package Drupal\acquia_contenthub\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\acquia_contenthub\Form\ContentHubDeleteClientConfirmForm uses AcquiaContentHubUnregisterHelperTrait
Expanded class hierarchy of ContentHubDeleteClientConfirmForm
1 file declares its use of ContentHubDeleteClientConfirmForm
- ClientDeleteConfirmForm.php in modules/
acquia_contenthub_publisher/ src/ Form/ Client/ ClientDeleteConfirmForm.php
1 string reference to 'ContentHubDeleteClientConfirmForm'
File
- src/
Form/ ContentHubDeleteClientConfirmForm.php, line 24
Namespace
Drupal\acquia_contenthub\FormView source
class ContentHubDeleteClientConfirmForm extends FormBase {
use AcquiaContentHubUnregisterHelperTrait;
/**
* The Content Hub connection manager.
*
* @var \Drupal\acquia_contenthub\ContentHubConnectionManager
*/
protected $chConnectionManager;
/**
* Event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* AcquiaContentHubUnregisterEvent event.
*
* @var \Drupal\acquia_contenthub\Event\AcquiaContentHubUnregisterEvent
*/
protected $event;
/**
* The client factory.
*
* @var \Drupal\acquia_contenthub\Client\ClientFactory
*/
protected $clientFactory;
/**
* ContentHubDeleteClientConfirmForm constructor.
*
* @param \Drupal\acquia_contenthub\ContentHubConnectionManager $ch_connection_manager
* The Content Hub connection manager service.
* @param \Drupal\acquia_contenthub\Client\ClientFactory $client_factory
* The Client Factory.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* Symfony event dispatcher.
*/
public function __construct(ContentHubConnectionManager $ch_connection_manager, ClientFactory $client_factory, EventDispatcherInterface $eventDispatcher) {
$this->chConnectionManager = $ch_connection_manager;
$this->clientFactory = $client_factory;
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/** @var \Drupal\acquia_contenthub\ContentHubConnectionManager $ch_connection_manager */
$ch_connection_manager = $container
->get('acquia_contenthub.connection_manager');
/** @var \Drupal\acquia_contenthub\Client\ClientFactory $client_factory */
$client_factory = $container
->get('acquia_contenthub.client.factory');
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
$event_dispatcher = $container
->get('event_dispatcher');
return new static($ch_connection_manager, $client_factory, $event_dispatcher);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) : array {
$webhook_uuid = $this
->getWebhookUuid();
if (empty($webhook_uuid)) {
$this
->messenger()
->addError($this
->t('Cannot find webhook uuid.'));
return $form;
}
$this
->dispatchEvent($webhook_uuid);
$orphaned_entities_amount = $this->event
->getOrphanedEntitiesAmount();
if ($orphaned_entities_amount !== 0) {
$form['delete_entities']['orphaned_entites'] = [
'#type' => 'details',
'#open' => TRUE,
'#description' => $this
->t('There are @count entities published from this client: @client. You have to delete/reoriginate those entities before proceeding with the unregistration. @blank
If you want to delete those entities and unregister the client, use the following drush command on the given client "drush ach-disconnect --delete=all".', [
'@count' => $orphaned_entities_amount,
'@client' => $this->event
->getClientName(),
'@blank' => new FormattableMarkup('<br>', []),
]),
'#title' => $this
->t('Un-register Acquia Content Hub'),
];
}
if ($this->event
->getOrphanedFilters()) {
$form['delete_filters'] = [
'#type' => 'details',
'#title' => $this
->t('After un-registration the following filters will be deleted:'),
'#open' => TRUE,
];
$form['delete_filters']['orphaned_filters'] = [
'#type' => 'table',
'#title' => $this
->t('Orphaned filters'),
'#header' => [
'Filter name',
'Filter UUID',
],
'#rows' => $this
->formatOrphanedFiltersTable($this->event
->getOrphanedFilters()),
];
if ($this
->checkDiscoveryRoute()) {
$form['actions']['redirect'] = [
'#type' => 'link',
'#title' => $this
->t('Go to Discovery Interface'),
'#url' => Url::fromRoute('acquia_contenthub_curation.discovery'),
'#attributes' => [
'class' => [
'button',
],
],
];
}
}
if (empty($this->event
->getOrphanedFilters()) && !$orphaned_entities_amount) {
$form['safe_message'] = [
'#markup' => $this
->t('Everything is in order, safe to proceed.'),
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Unregister'),
'#button_type' => 'primary',
'#attributes' => [
'disabled' => (bool) $orphaned_entities_amount,
],
];
$form['settings'] = [
'#type' => 'submit',
'#value' => $this
->t('Content Hub Settings'),
'#button_type' => 'primary',
'#name' => 'settings',
];
$form['subscription'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#button_type' => 'primary',
'#name' => 'subscription',
];
return $form;
}
/**
* Dispatches AcquiaContentHubUnregisterEvent.
*
* @param string $webhook_uuid
* Webhook uuid.
*/
public function dispatchEvent(string $webhook_uuid) {
$this->event = new AcquiaContentHubUnregisterEvent($webhook_uuid);
$this->eventDispatcher
->dispatch(AcquiaContentHubEvents::ACH_UNREGISTER, $this->event);
}
/**
* Get webhook UUID.
*
* @return string
* Webhook uuid.
*
* @throws \Exception
*/
public function getWebhookUuid() : string {
$client = $this->clientFactory
->getClient();
$settings = $client
->getSettings();
$remote_settings = $client
->getRemoteSettings();
foreach ($remote_settings['webhooks'] as $webhook) {
if ($webhook['client_name'] === $settings
->getName()) {
return $webhook['uuid'];
}
}
return '';
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#name'] === 'subscription') {
$form_state
->setRedirect('acquia_contenthub.subscription_settings');
return;
}
if ($form_state
->getTriggeringElement()['#name'] === 'settings') {
$form_state
->setRedirect('acquia_contenthub.admin_settings');
return;
}
$client = $this->clientFactory
->getClient();
if (!$client) {
$this
->messenger()
->addError("Couldn't instantiate client. Please check connection settings.");
$form_state
->setRedirect('acquia_contenthub.admin_settings');
return;
}
try {
$this->chConnectionManager
->unregister($this->event);
} catch (\Exception $e) {
$this
->messenger()
->addError($this
->t('Error during unregistration: @error_message', [
'@error_message' => $e
->getMessage(),
]));
return;
}
$form_state
->setRedirect('acquia_contenthub.admin_settings');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return "contenthub_delete_client_confirmation";
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaContentHubUnregisterHelperTrait:: |
public | function | Checks if Discovery Interface route exists. | |
AcquiaContentHubUnregisterHelperTrait:: |
protected | function | Format rows for render array. | |
ContentHubDeleteClientConfirmForm:: |
protected | property | The Content Hub connection manager. | |
ContentHubDeleteClientConfirmForm:: |
protected | property | The client factory. | |
ContentHubDeleteClientConfirmForm:: |
protected | property | AcquiaContentHubUnregisterEvent event. | |
ContentHubDeleteClientConfirmForm:: |
protected | property | Event dispatcher. | |
ContentHubDeleteClientConfirmForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
1 |
ContentHubDeleteClientConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ContentHubDeleteClientConfirmForm:: |
public | function | Dispatches AcquiaContentHubUnregisterEvent. | 1 |
ContentHubDeleteClientConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
1 |
ContentHubDeleteClientConfirmForm:: |
public | function | Get webhook UUID. | 1 |
ContentHubDeleteClientConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ContentHubDeleteClientConfirmForm:: |
public | function | ContentHubDeleteClientConfirmForm constructor. | |
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. | |
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. |