Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / search / src / Form / ReindexConfirm.php
1 <?php
2
3 namespace Drupal\search\Form;
4
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Provides the search reindex confirmation form.
11  *
12  * @internal
13  */
14 class ReindexConfirm extends ConfirmFormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'search_reindex_confirm';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function getQuestion() {
27     return $this->t('Are you sure you want to re-index the site?');
28   }
29
30   /**
31    * {@inheritdoc}
32    */
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.");
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function getConfirmText() {
41     return $this->t('Re-index site');
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getCancelText() {
48     return $this->t('Cancel');
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getCancelUrl() {
55     return new Url('entity.search_page.collection');
56   }
57
58   /**
59    * {@inheritdoc}
60    */
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();
67       }
68       drupal_set_message($this->t('All search indexes will be rebuilt.'));
69       $form_state->setRedirectUrl($this->getCancelUrl());
70     }
71   }
72
73 }