You are here

public function ContentHubDeleteClientConfirmForm::buildForm in Acquia Content Hub 8.2

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

1 call to ContentHubDeleteClientConfirmForm::buildForm()
ClientDeleteConfirmForm::buildForm in modules/acquia_contenthub_publisher/src/Form/Client/ClientDeleteConfirmForm.php
Form constructor.
1 method overrides ContentHubDeleteClientConfirmForm::buildForm()
ClientDeleteConfirmForm::buildForm in modules/acquia_contenthub_publisher/src/Form/Client/ClientDeleteConfirmForm.php
Form constructor.

File

src/Form/ContentHubDeleteClientConfirmForm.php, line 94

Class

ContentHubDeleteClientConfirmForm
Class ContentHubDeleteClientConfirmForm.

Namespace

Drupal\acquia_contenthub\Form

Code

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;
}