3 namespace Drupal\search\Form;
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
10 * Provides the search reindex confirmation form.
14 class ReindexConfirm extends ConfirmFormBase {
19 public function getFormId() {
20 return 'search_reindex_confirm';
26 public function getQuestion() {
27 return $this->t('Are you sure you want to re-index the site?');
33 public function getDescription() {
34 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.");
40 public function getConfirmText() {
41 return $this->t('Re-index site');
47 public function getCancelText() {
48 return $this->t('Cancel');
54 public function getCancelUrl() {
55 return new Url('entity.search_page.collection');
61 public function submitForm(array &$form, FormStateInterface $form_state) {
62 if ($form['confirm']) {
63 // Ask each active search page to mark itself for re-index.
64 $search_page_repository = \Drupal::service('search.search_page_repository');
65 foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
66 $entity->getPlugin()->markForReindex();
68 drupal_set_message($this->t('All search indexes will be rebuilt.'));
69 $form_state->setRedirectUrl($this->getCancelUrl());