3 namespace Drupal\search\Form;
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
10 * Provides the search reindex confirmation form.
12 class ReindexConfirm extends ConfirmFormBase {
17 public function getFormId() {
18 return 'search_reindex_confirm';
24 public function getQuestion() {
25 return $this->t('Are you sure you want to re-index the site?');
31 public function getDescription() {
32 return $this->t("This will re-index content in the search indexes of all active search pages. Searching will continue to work, but new content won't be indexed until all existing content has been re-indexed. This action cannot be undone.");
38 public function getConfirmText() {
39 return $this->t('Re-index site');
45 public function getCancelText() {
46 return $this->t('Cancel');
52 public function getCancelUrl() {
53 return new Url('entity.search_page.collection');
59 public function submitForm(array &$form, FormStateInterface $form_state) {
60 if ($form['confirm']) {
61 // Ask each active search page to mark itself for re-index.
62 $search_page_repository = \Drupal::service('search.search_page_repository');
63 foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
64 $entity->getPlugin()->markForReindex();
66 drupal_set_message($this->t('All search indexes will be rebuilt.'));
67 $form_state->setRedirectUrl($this->getCancelUrl());