You are here

public function SavedSearchTypeDeleteConfirmForm::buildForm in Search API Saved Searches 8

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 EntityConfirmFormBase::buildForm

File

src/Form/SavedSearchTypeDeleteConfirmForm.php, line 64

Class

SavedSearchTypeDeleteConfirmForm
Provides a form for deleting saved search types.

Namespace

Drupal\search_api_saved_searches\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $num_searches = $this->entityTypeManager
    ->getStorage('search_api_saved_search')
    ->getQuery()
    ->condition('type', $this->entity
    ->id())
    ->count()
    ->accessCheck(FALSE)
    ->execute();
  if ($num_searches) {
    $caption = '<p>' . $this
      ->formatPlural($num_searches, '%type is used by 1 saved search on your site. You cannot remove this saved search type until you have removed all of the %type saved searches.', '%type is used by @count saved searches on your site. You cannot remove this saved search type until you have removed all of the %type saved searches.', [
      '%type' => $this->entity
        ->label(),
    ]) . '</p>';
    $form['#title'] = $this
      ->getQuestion();
    $form['description'] = [
      '#markup' => $caption,
    ];
    return $form;
  }
  $form = parent::buildForm($form, $form_state);

  // Add information about the changes to dependent entities.
  // @see \Drupal\Core\Entity\EntityDeleteForm::buildForm()

  /** @var \Drupal\search_api_saved_searches\SavedSearchTypeInterface $entity */
  $entity = $this
    ->getEntity();
  $this
    ->addDependencyListsToForm($form, $entity
    ->getConfigDependencyKey(), $this
    ->getConfigNamesToDelete($entity), $this
    ->getConfigManager(), $this->entityTypeManager);
  return $form;
}