Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\search\Form;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Form\ConfirmFormBase;
|
Chris@0
|
6 use Drupal\Core\Form\FormStateInterface;
|
Chris@0
|
7 use Drupal\Core\Url;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Provides the search reindex confirmation form.
|
Chris@14
|
11 *
|
Chris@14
|
12 * @internal
|
Chris@0
|
13 */
|
Chris@0
|
14 class ReindexConfirm extends ConfirmFormBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * {@inheritdoc}
|
Chris@0
|
18 */
|
Chris@0
|
19 public function getFormId() {
|
Chris@0
|
20 return 'search_reindex_confirm';
|
Chris@0
|
21 }
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * {@inheritdoc}
|
Chris@0
|
25 */
|
Chris@0
|
26 public function getQuestion() {
|
Chris@0
|
27 return $this->t('Are you sure you want to re-index the site?');
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * {@inheritdoc}
|
Chris@0
|
32 */
|
Chris@0
|
33 public function getDescription() {
|
Chris@0
|
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.");
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * {@inheritdoc}
|
Chris@0
|
39 */
|
Chris@0
|
40 public function getConfirmText() {
|
Chris@0
|
41 return $this->t('Re-index site');
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * {@inheritdoc}
|
Chris@0
|
46 */
|
Chris@0
|
47 public function getCancelText() {
|
Chris@0
|
48 return $this->t('Cancel');
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * {@inheritdoc}
|
Chris@0
|
53 */
|
Chris@0
|
54 public function getCancelUrl() {
|
Chris@0
|
55 return new Url('entity.search_page.collection');
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * {@inheritdoc}
|
Chris@0
|
60 */
|
Chris@0
|
61 public function submitForm(array &$form, FormStateInterface $form_state) {
|
Chris@0
|
62 if ($form['confirm']) {
|
Chris@0
|
63 // Ask each active search page to mark itself for re-index.
|
Chris@0
|
64 $search_page_repository = \Drupal::service('search.search_page_repository');
|
Chris@0
|
65 foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
|
Chris@0
|
66 $entity->getPlugin()->markForReindex();
|
Chris@0
|
67 }
|
Chris@17
|
68 $this->messenger()->addStatus($this->t('All search indexes will be rebuilt.'));
|
Chris@0
|
69 $form_state->setRedirectUrl($this->getCancelUrl());
|
Chris@0
|
70 }
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 }
|