Issue #2032235 by elachlan: Fixed SearchSettingsForm implements CMI incorrectly.

8.0.x
Alex Pott 2013-07-20 02:31:56 +01:00
parent ede56ec522
commit be35585c26
1 changed files with 31 additions and 30 deletions

View File

@ -7,7 +7,8 @@
namespace Drupal\search\Form;
use Drupal\system\SystemConfigFormBase;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Config\Context\ContextInterface;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Component\Utility\NestedArray;
@ -17,13 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Configure search settings for this site.
*/
class SearchSettingsForm extends SystemConfigFormBase {
/**
* A configuration object with the current search settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $searchSettings;
/**
* The module handler.
*
@ -39,15 +33,19 @@ class SearchSettingsForm extends SystemConfigFormBase {
protected $state;
/**
* Constructs a \Drupal\user\SearchSettingsForm object.
* Constructs a \Drupal\search\Form\SearchSettingsForm object.
*
* @param \Drupal\Core\Config\Config $search_settings
* The configuration object that manages search settings.
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The configuration factory object that manages search settings.
* @param \Drupal\Core\Config\Context\ContextInterface $context
* The context interface
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* The module handler
* @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state
* The state key/value store interface, gives access to state based config settings.
*/
public function __construct(Config $search_settings, ModuleHandler $module_handler, KeyValueStoreInterface $state) {
$this->searchSettings = $search_settings;
public function __construct(ConfigFactory $config_factory, ContextInterface $context, ModuleHandler $module_handler, KeyValueStoreInterface $state) {
parent::__construct($config_factory, $context);
$this->moduleHandler = $module_handler;
$this->state = $state;
}
@ -57,9 +55,10 @@ class SearchSettingsForm extends SystemConfigFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')->get('search.settings'),
$container->get('config.factory'),
$container->get('config.context.free'),
$container->get('module_handler'),
$container->get('keyvalue')->get('state')
$container->get('state')
);
}
@ -89,10 +88,11 @@ class SearchSettingsForm extends SystemConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('search.settings');
// Collect some stats
$remaining = 0;
$total = 0;
foreach ($this->searchSettings->get('active_modules') as $module) {
foreach ($config->get('active_modules') as $module) {
if ($status = $this->moduleHandler->invoke($module, 'search_status')) {
$remaining += $status['remaining'];
$total += $status['total'];
@ -124,7 +124,7 @@ class SearchSettingsForm extends SystemConfigFormBase {
$form['indexing_throttle']['cron_limit'] = array(
'#type' => 'select',
'#title' => t('Number of items to index per cron run'),
'#default_value' => $this->searchSettings->get('index.cron_limit'),
'#default_value' => $config->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' => url('admin/reports/status')))
);
@ -139,7 +139,7 @@ class SearchSettingsForm extends SystemConfigFormBase {
$form['indexing_settings']['minimum_word_size'] = array(
'#type' => 'number',
'#title' => t('Minimum word length to index'),
'#default_value' => $this->searchSettings->get('index.minimum_word_size'),
'#default_value' => $config->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).')
@ -147,7 +147,7 @@ class SearchSettingsForm extends SystemConfigFormBase {
$form['indexing_settings']['overlap_cjk'] = array(
'#type' => 'checkbox',
'#title' => t('Simple CJK handling'),
'#default_value' => $this->searchSettings->get('index.overlap_cjk'),
'#default_value' => $config->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.')
);
@ -160,20 +160,20 @@ class SearchSettingsForm extends SystemConfigFormBase {
'#type' => 'checkboxes',
'#title' => t('Active modules'),
'#title_display' => 'invisible',
'#default_value' => $this->searchSettings->get('active_modules'),
'#default_value' => $config->get('active_modules'),
'#options' => $module_options,
'#description' => t('Choose which search modules are active from the available modules.')
);
$form['active']['default_module'] = array(
'#title' => t('Default search module'),
'#type' => 'radios',
'#default_value' => $this->searchSettings->get('default_module'),
'#default_value' => $config->get('default_module'),
'#options' => $module_options,
'#description' => t('Choose which search module is the default.')
);
// Per module settings
foreach ($this->searchSettings->get('active_modules') as $module) {
foreach ($config->get('active_modules') as $module) {
$added_form = $this->moduleHandler->invoke($module, 'search_admin');
if (is_array($added_form)) {
$form = NestedArray::mergeDeep($form, $added_form);
@ -207,16 +207,17 @@ class SearchSettingsForm extends SystemConfigFormBase {
*/
public function submitForm(array &$form, array &$form_state) {
parent::submitForm($form, $form_state);
$config = $this->configFactory->get('search.settings');
// If these settings change, the index needs to be rebuilt.
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']);
if (($config->get('index.minimum_word_size') != $form_state['values']['minimum_word_size']) || ($config->get('index.overlap_cjk') != $form_state['values']['overlap_cjk'])) {
$config->set('index.minimum_word_size', $form_state['values']['minimum_word_size']);
$config->set('index.overlap_cjk', $form_state['values']['overlap_cjk']);
drupal_set_message(t('The index will be rebuilt.'));
search_reindex();
}
$this->searchSettings->set('index.cron_limit', $form_state['values']['cron_limit']);
$this->searchSettings->set('default_module', $form_state['values']['default_module']);
$config->set('index.cron_limit', $form_state['values']['cron_limit']);
$config->set('default_module', $form_state['values']['default_module']);
// Check whether we are resetting the values.
if ($form_state['triggering_element']['#value'] == t('Reset to defaults')) {
@ -225,12 +226,12 @@ class SearchSettingsForm extends SystemConfigFormBase {
else {
$new_modules = array_filter($form_state['values']['active_modules']);
}
if ($this->searchSettings->get('active_modules') != $new_modules) {
$this->searchSettings->set('active_modules', $new_modules);
if ($config->get('active_modules') != $new_modules) {
$config->set('active_modules', $new_modules);
drupal_set_message(t('The active search modules have been changed.'));
$this->state->set('menu_rebuild_needed', TRUE);
}
$this->searchSettings->save();
$config->save();
}
/**