From 96edb7822dbae78de05e3dc1dae2d7dc6987c546 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 26 Sep 2013 01:51:34 +0200 Subject: [PATCH] Issue #2078005 by Ivan Zugec: Modernize search.module forms. --- .../lib/Drupal/search/Form/ReindexConfirm.php | 10 ++--- .../Drupal/search/Form/SearchBlockForm.php | 20 +++------ .../Drupal/search/Form/SearchSettingsForm.php | 44 +++++++++---------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php b/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php index 20a484bff632..72df4e9ad59a 100644 --- a/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php +++ b/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php @@ -25,28 +25,28 @@ public function getFormID() { * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion(). */ public function getQuestion() { - return t('Are you sure you want to re-index the site?'); + return $this->t('Are you sure you want to re-index the site?'); } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription(). */ public function getDescription() { - return t('The search index is not cleared but systematically updated to reflect the new settings. 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.'); + return $this->t('The search index is not cleared but systematically updated to reflect the new settings. 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.'); } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). */ public function getConfirmText() { - return t('Re-index site'); + return $this->t('Re-index site'); } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getCancelText(). */ public function getCancelText() { - return t('Cancel'); + return $this->t('Cancel'); } /** @@ -64,7 +64,7 @@ public function getCancelRoute() { public function submitForm(array &$form, array &$form_state) { if ($form['confirm']) { search_reindex(); - drupal_set_message(t('The index will be rebuilt.')); + drupal_set_message($this->t('The index will be rebuilt.')); $form_state['redirect'] = 'admin/config/search/settings'; return; } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php index eaf2c6012f1a..1f5876b6b958 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php @@ -8,12 +8,13 @@ namespace Drupal\search\Form; use Drupal\Core\Form\FormInterface; +use Drupal\Core\Form\FormBase; use Symfony\Component\HttpFoundation\Request; /** * Builds the search form for the search block. */ -class SearchBlockForm implements FormInterface { +class SearchBlockForm extends FormBase implements FormInterface { /** * The current request. @@ -38,25 +39,18 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $form['search_block_form'] = array( '#type' => 'search', - '#title' => t('Search'), + '#title' => $this->t('Search'), '#title_display' => 'invisible', '#size' => 15, '#default_value' => '', - '#attributes' => array('title' => t('Enter the terms you wish to search for.')), + '#attributes' => array('title' => $this->t('Enter the terms you wish to search for.')), ); $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search')); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search')); return $form; } - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - // No validation necessary at this time. - } - /** * {@inheritdoc} */ @@ -75,7 +69,7 @@ public function submitForm(array &$form, array &$form_state) { // "field is required" because the search keywords field has no title. // The error message would also complain about a missing #title field.) if ($form_state['values']['search_block_form'] == '') { - form_set_error('keys', t('Please enter some keywords.')); + form_set_error('keys', $this->t('Please enter some keywords.')); } $form_id = $form['form_id']['#value']; @@ -84,7 +78,7 @@ public function submitForm(array &$form, array &$form_state) { $form_state['redirect'] = 'search/' . $info['path'] . '/' . trim($form_state['values'][$form_id]); } else { - form_set_error(NULL, t('Search is currently disabled.'), 'error'); + form_set_error(NULL, $this->t('Search is currently disabled.'), 'error'); } } } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php index bf37009c79d1..b91b588f3bd3 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php @@ -123,15 +123,15 @@ public function buildForm(array $form, array &$form_state) { $this->moduleHandler->loadAllIncludes('admin.inc'); $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.'); $percentage = ((int) min(100, 100 * ($total - $remaining) / max(1, $total))) . '%'; - $status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>'; + $status = '<p><strong>' . $this->t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>'; $form['status'] = array( '#type' => 'details', - '#title' => t('Indexing status'), + '#title' => $this->t('Indexing status'), ); $form['status']['status'] = array('#markup' => $status); $form['status']['wipe'] = array( '#type' => 'submit', - '#value' => t('Re-index site'), + '#value' => $this->t('Re-index site'), '#submit' => array(array($this, 'searchAdminReindexSubmit')), ); @@ -140,57 +140,57 @@ public function buildForm(array $form, array &$form_state) { // Indexing throttle: $form['indexing_throttle'] = array( '#type' => 'details', - '#title' => t('Indexing throttle') + '#title' => $this->t('Indexing throttle') ); $form['indexing_throttle']['cron_limit'] = array( '#type' => 'select', - '#title' => t('Number of items to index per cron run'), + '#title' => $this->t('Number of items to index per cron run'), '#default_value' => $this->searchSettings->get('index.cron_limit'), '#options' => $items, - '#description' => t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => $this->url('system.status'))) + '#description' => $this->t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => $this->url('system.status'))) ); // Indexing settings: $form['indexing_settings'] = array( '#type' => 'details', - '#title' => t('Indexing settings') + '#title' => $this->t('Indexing settings') ); $form['indexing_settings']['info'] = array( - '#markup' => t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>') + '#markup' => $this->t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>') ); $form['indexing_settings']['minimum_word_size'] = array( '#type' => 'number', - '#title' => t('Minimum word length to index'), + '#title' => $this->t('Minimum word length to index'), '#default_value' => $this->searchSettings->get('index.minimum_word_size'), '#min' => 1, '#max' => 1000, - '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).') + '#description' => $this->t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).') ); $form['indexing_settings']['overlap_cjk'] = array( '#type' => 'checkbox', - '#title' => t('Simple CJK handling'), + '#title' => $this->t('Simple CJK handling'), '#default_value' => $this->searchSettings->get('index.overlap_cjk'), - '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.') + '#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.') ); $form['active'] = array( '#type' => 'details', - '#title' => t('Active search plugins') + '#title' => $this->t('Active search plugins') ); $options = $this->getOptions(); $form['active']['active_plugins'] = array( '#type' => 'checkboxes', - '#title' => t('Active plugins'), + '#title' => $this->t('Active plugins'), '#title_display' => 'invisible', '#default_value' => $this->searchSettings->get('active_plugins'), '#options' => $options, - '#description' => t('Choose which search plugins are active from the available plugins.') + '#description' => $this->t('Choose which search plugins are active from the available plugins.') ); $form['active']['default_plugin'] = array( - '#title' => t('Default search plugin'), + '#title' => $this->t('Default search plugin'), '#type' => 'radios', '#default_value' => $this->searchSettings->get('default_plugin'), '#options' => $options, - '#description' => t('Choose which search plugin is the default.') + '#description' => $this->t('Choose which search plugin is the default.') ); // Per plugin settings. @@ -211,11 +211,11 @@ public function validateForm(array &$form, array &$form_state) { parent::validateForm($form, $form_state); // Check whether we selected a valid default. - if ($form_state['triggering_element']['#value'] != t('Reset to defaults')) { + if ($form_state['triggering_element']['#value'] != $this->t('Reset to defaults')) { $new_plugins = array_filter($form_state['values']['active_plugins']); $default = $form_state['values']['default_plugin']; if (!in_array($default, $new_plugins, TRUE)) { - form_set_error('default_plugin', t('Your default search plugin is not selected as an active plugin.')); + form_set_error('default_plugin', $this->t('Your default search plugin is not selected as an active plugin.')); } } } @@ -230,7 +230,7 @@ public function submitForm(array &$form, array &$form_state) { if (($this->searchSettings->get('index.minimum_word_size') != $form_state['values']['minimum_word_size']) || ($this->searchSettings->get('index.overlap_cjk') != $form_state['values']['overlap_cjk'])) { $this->searchSettings->set('index.minimum_word_size', $form_state['values']['minimum_word_size']); $this->searchSettings->set('index.overlap_cjk', $form_state['values']['overlap_cjk']); - drupal_set_message(t('The index will be rebuilt.')); + drupal_set_message($this->t('The index will be rebuilt.')); search_reindex(); } $this->searchSettings->set('index.cron_limit', $form_state['values']['cron_limit']); @@ -242,7 +242,7 @@ public function submitForm(array &$form, array &$form_state) { } // Check whether we are resetting the values. - if ($form_state['triggering_element']['#value'] == t('Reset to defaults')) { + if ($form_state['triggering_element']['#value'] == $this->t('Reset to defaults')) { $new_plugins = array('node_search', 'user_search'); } else { @@ -250,7 +250,7 @@ public function submitForm(array &$form, array &$form_state) { } if ($this->searchSettings->get('active_plugins') != $new_plugins) { $this->searchSettings->set('active_plugins', $new_plugins); - drupal_set_message(t('The active search plugins have been changed.')); + drupal_set_message($this->t('The active search plugins have been changed.')); $this->state->set('menu_rebuild_needed', TRUE); } $this->searchSettings->save(); -- GitLab