diff --git a/core/modules/node/config/search.plugin.node_search.yml b/core/modules/node/config/search.plugin.node_search.yml new file mode 100644 index 0000000..102d659 --- /dev/null +++ b/core/modules/node/config/search.plugin.node_search.yml @@ -0,0 +1,5 @@ +rank: + promote: 0 + recent: 0 + relevance: 0 + sticky: 0 diff --git a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php index 0dbd1ac..e68273a 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -272,8 +272,8 @@ protected function addNodeRankings(SelectExtender $query) { if ($ranking = $this->moduleHandler->invokeAll('ranking')) { $tables = &$query->getTables(); foreach ($ranking as $rank => $values) { - // @todo - move rank out of drupal variables. - if ($node_rank = variable_get('node_rank_' . $rank, 0)) { + $node_rank = \Drupal::config('search.plugin.node_search')->get('rank.' . $rank); + if (!empty($node_rank)) { // If the table defined in the ranking isn't already joined, then add it. if (isset($values['join']) && !isset($tables[$values['join']['alias']])) { $query->addJoin($values['join']['type'], $values['join']['table'], $values['join']['alias'], $values['join']['on']); @@ -535,7 +535,9 @@ public function buildConfigurationForm(array $form, array &$form_state) { '#title' => $values['title'], '#type' => 'select', '#options' => $options, - '#default_value' => variable_get('node_rank_' . $var, 0), + // We shouldn't really provide a default in this way, but the current + // architecture doesn't allow us to specify all defaults in .yml files. + '#default_value' => \Drupal::config('search.plugin.node_search')->get('rank.' . $var) ?: 0, ); } return $form; @@ -551,12 +553,14 @@ public function validateConfigurationForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, array &$form_state) { - foreach ($this->moduleHandler->invokeAll('ranking') as $var => $values) { - if (isset($form_state['values']['node_rank_' . $var])) { - // @todo Fix when https://drupal.org/node/1831632 is in. - variable_set('node_rank_' . $var, $form_state['values']['node_rank_' . $var]); - } + $config = \Drupal::config('search.plugin.node_search'); + $rank = array(); + foreach (array_keys($this->moduleHandler->invokeAll('ranking')) as $var) { + $rank[$var] = intval($form_state['values']['node_rank_' . $var]); } + ksort($rank); + $config->set('rank', $rank); + $config->save(); } } diff --git a/core/modules/node/node.install b/core/modules/node/node.install index b240ecc..1a8f55f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -450,12 +450,6 @@ function node_uninstall() { \Drupal::config('language.settings')->clear('node. ' . $type . '.language.default_configuration')->save(); } - // Delete node search ranking variables. - variable_del('node_rank_relevance'); - variable_del('node_rank_sticky'); - variable_del('node_rank_promote'); - variable_del('node_rank_recent'); - // Delete remaining general module variables. \Drupal::state()->delete('node.node_access_needs_rebuild'); variable_del('node_recent_block_count'); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php index bb4e6ba..8682cd5 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php @@ -114,10 +114,13 @@ public function testRankings() { array_pop($node_ranks); array_pop($node_ranks); foreach ($node_ranks as $node_rank) { + $config = \Drupal::config('search.plugin.node_search'); // Disable all relevancy rankings except the one we are testing. foreach ($node_ranks as $var) { - variable_set('node_rank_' . $var, $var == $node_rank ? 10 : 0); + $config->set('rank.' . $var, $var == $node_rank ? 10 : 0); } + $config->save(); + $this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); // Do the search and assert the results. $this->nodeSearchPlugin->setSearch('rocks', array(), array()); $set = $this->nodeSearchPlugin->execute(); @@ -172,9 +175,12 @@ public function testHTMLRankings() { // Disable all other rankings. $node_ranks = array('sticky', 'promote', 'recent', 'comments', 'views'); + $config = \Drupal::config('search.plugin.node_search'); foreach ($node_ranks as $node_rank) { - variable_set('node_rank_' . $node_rank, 0); + $config->set('rank.' . $node_rank, 0); } + $config->save(); + $this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $this->nodeSearchPlugin->setSearch('rocks', array(), array()); // Do the search and assert the results. $set = $this->nodeSearchPlugin->execute(); @@ -245,11 +251,13 @@ function testDoubleRankings() { // Set up for ranking sticky and lots of comments; make sure others are // disabled. $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views'); + $config = \Drupal::config('search.plugin.node_search'); foreach ($node_ranks as $var) { $value = ($var == 'sticky' || $var == 'comments') ? 10 : 0; - variable_set('node_rank_' . $var, $value); + $config->set('rank.' . $var, $value); } - + $config->save(); + $this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); // Do the search and assert the results. $this->nodeSearchPlugin->setSearch('rocks', array(), array()); // Do the search and assert the results. diff --git a/core/modules/system/tests/upgrade/drupal-7.system.database.php b/core/modules/system/tests/upgrade/drupal-7.system.database.php index f15d406..836a828 100644 --- a/core/modules/system/tests/upgrade/drupal-7.system.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php @@ -163,6 +163,30 @@ 'name' => 'aggregator_summary_items', 'value' => 'i:5;', )) + ->values(array( + 'name' => 'node_rank_comments', + 'value' => 'i:-2;', + )) + ->values(array( + 'name' => 'node_rank_promote', + 'value' => 'i:10;', + )) + ->values(array( + 'name' => 'node_rank_recent', + 'value' => 'i:2;', + )) + ->values(array( + 'name' => 'node_rank_relevance', + 'value' => 'i:8;', + )) + ->values(array( + 'name' => 'node_rank_sticky', + 'value' => 'i:3;', + )) + ->values(array( + 'name' => 'node_rank_views', + 'value' => 'i:5;', + )) ->execute(); db_update('variable')