diff --git a/core/modules/node/config/node.search.yml b/core/modules/node/config/node.search.yml
new file mode 100644
index 0000000..5aa4eb4
--- /dev/null
+++ b/core/modules/node/config/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 bf987e6..f2d1541 100644
--- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php
+++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php
@@ -270,9 +270,10 @@ public function execute() {
protected function addNodeRankings(SelectExtender $query) {
if ($ranking = $this->moduleHandler->invokeAll('ranking')) {
$tables = &$query->getTables();
+ $ranks = Drupal::config('node.search')->get('rank');
foreach ($ranking as $rank => $values) {
- // @todo - move rank out of drupal variables.
- if ($node_rank = variable_get('node_rank_' . $rank, 0)) {
+ if (!empty($ranks[$rank])) {
+ $node_rank = $ranks[$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']);
@@ -521,20 +522,29 @@ public function addToAdminForm(array &$form, array &$form_state) {
$form['content_ranking'] = array(
'#type' => 'details',
'#title' => t('Content ranking'),
+ '#tree' => TRUE,
);
- $form['content_ranking']['#theme'] = 'node_search_admin';
$form['content_ranking']['info'] = array(
- '#value' => '' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . ''
+ '#markup' => '' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . ''
+ );
+ $form['content_ranking']['factors'] = array(
+ '#type' => 'table',
+ '#header' => array(t('Factor'), t('Weight')),
);
// Note: reversed to reflect that higher number = higher ranking.
$options = drupal_map_assoc(range(0, 10));
+ $ranks = Drupal::config('node.search')->get('rank');
foreach ($this->moduleHandler->invokeAll('ranking') as $var => $values) {
- $form['content_ranking']['factors']['node_rank_' . $var] = array(
+ $form['content_ranking']['factors'][$var]['title'] = array(
+ '#markup' => $values['title'],
+ );
+ $form['content_ranking']['factors'][$var]['value'] = array(
'#title' => $values['title'],
+ '#title_display' => 'invisible',
'#type' => 'select',
'#options' => $options,
- '#default_value' => variable_get('node_rank_' . $var, 0),
+ '#default_value' => isset($ranks[$var]) ? $ranks[$var] : 0,
);
}
}
@@ -543,12 +553,10 @@ public function addToAdminForm(array &$form, array &$form_state) {
* {@inheritdoc}
*/
public function submitAdminForm(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]);
- }
- }
- }
+ $ranks = array_map(function($row) {
+ return $row['value'];
+ }, $form_state['values']['content_ranking']['factors']);
+ Drupal::config('node.search')->set('rank', $ranks)->save();
+ }
}
diff --git a/core/modules/node/node.install b/core/modules/node/node.install
index 02cc7a0..c823373 100644
--- a/core/modules/node/node.install
+++ b/core/modules/node/node.install
@@ -422,12 +422,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/node/node.module b/core/modules/node/node.module
index 6a86317..a4922dc 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -149,9 +149,6 @@ function node_theme() {
'render element' => 'elements',
'template' => 'node',
),
- 'node_search_admin' => array(
- 'render element' => 'form',
- ),
'node_add_list' => array(
'variables' => array('content' => NULL),
'file' => 'node.pages.inc',
@@ -862,40 +859,6 @@ function node_user_predelete($account) {
}
/**
- * Returns HTML for the content ranking part of the search settings admin page.
- *
- * @param $variables
- * An associative array containing:
- * - form: A render element representing the form.
- *
- * @see node_search_admin()
- * @ingroup themeable
- */
-function theme_node_search_admin($variables) {
- $form = $variables['form'];
-
- $output = drupal_render($form['info']);
-
- $header = array(t('Factor'), t('Weight'));
- foreach (element_children($form['factors']) as $key) {
- $row = array();
- $row[] = $form['factors'][$key]['#title'];
- $form['factors'][$key]['#title_display'] = 'invisible';
- $row[] = drupal_render($form['factors'][$key]);
- $rows[] = $row;
- }
- $table = array(
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- );
- $output .= drupal_render($table);
-
- $output .= drupal_render_children($form);
- return $output;
-}
-
-/**
* Access callback: Checks node revision access.
*
* @param \Drupal\Core\Entity\EntityInterface $node
diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
index c7055f3..e4626c5 100644
--- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
+++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
@@ -112,9 +112,11 @@ public function testRankings() {
array_pop($node_ranks);
foreach ($node_ranks as $node_rank) {
// Disable all relevancy rankings except the one we are testing.
+ $ranks = array();
foreach ($node_ranks as $var) {
- variable_set('node_rank_' . $var, $var == $node_rank ? 10 : 0);
+ $ranks[$var] = $var == $node_rank ? 10 : 0;
}
+ \Drupal::config('node.search')->set('rank', $ranks)->save();
// Do the search and assert the results.
$this->nodeSearchPlugin->setSearch('rocks', array(), array());
$set = $this->nodeSearchPlugin->execute();
@@ -168,10 +170,8 @@ public function testHTMLRankings() {
$this->refreshVariables();
// Disable all other rankings.
- $node_ranks = array('sticky', 'promote', 'recent', 'comments', 'views');
- foreach ($node_ranks as $node_rank) {
- variable_set('node_rank_' . $node_rank, 0);
- }
+ $ranks = array('sticky' => 0, 'promote' => 0, 'recent' => 0, 'comments' => 0, 'views' => 0);
+ \Drupal::config('node.search')->set('rank', $ranks)->save();
$this->nodeSearchPlugin->setSearch('rocks', array(), array());
// Do the search and assert the results.
$set = $this->nodeSearchPlugin->execute();
@@ -241,11 +241,8 @@ 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');
- foreach ($node_ranks as $var) {
- $value = ($var == 'sticky' || $var == 'comments') ? 10 : 0;
- variable_set('node_rank_' . $var, $value);
- }
+ $ranks = array('sticky' => 10, 'promote' => 0, 'relevance' => 0, 'recent' => 0, 'comments' => 10, 'views' => 0);
+ \Drupal::config('node.search')->set('rank', $ranks)->save();
// Do the search and assert the results.
$this->nodeSearchPlugin->setSearch('rocks', array(), array());
diff --git a/core/modules/search/search.install b/core/modules/search/search.install
index 824a624..5c4f158 100644
--- a/core/modules/search/search.install
+++ b/core/modules/search/search.install
@@ -214,3 +214,17 @@ function search_update_8001() {
));
db_add_primary_key('search_index', array('word', 'sid', 'langcode', 'type'));
}
+
+/**
+ * Moves node search rank variables to node.search settings.
+ */
+function search_update_8002() {
+ update_variables_to_config('node.search', array(
+ 'node_rank_relevance' => 'rank.relevance',
+ 'node_rank_sticky' => 'rank.sticky',
+ 'node_rank_promote' => 'rank.promote',
+ 'node_rank_recent' => 'rank.recent',
+ 'node_rank_comments' => 'rank.comments',
+ 'node_rank_views' => 'rank.views',
+ ));
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
index 4b22f93..769411a 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
@@ -169,6 +169,12 @@ public function testVariableUpgrade() {
'source.list_max' => 5,
);
+ $expected_config['node.search'] = array(
+ 'rank.promote' => 10,
+ 'rank.views' => 5,
+ 'rank.comments' => -2,
+ );
+
foreach ($expected_config as $file => $values) {
$config = \Drupal::config($file);
$this->verbose(print_r($config->get(), TRUE));
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..b87115c 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,18 @@
'name' => 'aggregator_summary_items',
'value' => 'i:5;',
))
+ ->values(array(
+ 'name' => 'node_rank_promote',
+ 'value' => 'i:10;',
+ ))
+ ->values(array(
+ 'name' => 'node_rank_views',
+ 'value' => 'i:5;',
+ ))
+ ->values(array(
+ 'name' => 'node_rank_comments',
+ 'value' => 'i:-2;',
+ ))
->execute();
db_update('variable')