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