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 f1dfc39..e68273a 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -535,7 +535,9 @@ public function buildConfigurationForm(array $form, array &$form_state) { '#title' => $values['title'], '#type' => 'select', '#options' => $options, - '#default_value' => \Drupal::config('search.plugin.node_search')->get('rank.' . $var), + // 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; @@ -552,11 +554,12 @@ public function validateConfigurationForm(array &$form, array &$form_state) { */ public function submitConfigurationForm(array &$form, array &$form_state) { $config = \Drupal::config('search.plugin.node_search'); - foreach ($this->moduleHandler->invokeAll('ranking') as $var => $values) { - if (isset($form_state['values']['node_rank_' . $var])) { - $config->set('rank.' . $var, $form_state['values']['node_rank_' . $var]); - } + $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 817fea2..1a8f55f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -6,7 +6,6 @@ */ use Drupal\Component\Uuid\Uuid; -use Drupal\Core\Config\FileStorage; use Drupal\Core\Language\Language; /** @@ -1159,38 +1158,6 @@ function node_update_8021() { } /** - * Converts node search ranking variables to config. - * - * @ingroup config_upgrade - */ -function node_update_8022() { - if (\Drupal::moduleHandler()->moduleExists('search')) { - $config_name = 'search.plugin.node_search'; - $config = Drupal::config($config_name); - - // Load and set default configuration values. - $file = new FileStorage(drupal_get_path('module', 'node') . '/config'); - $default_data = $file->read($config_name); - - // Apply the default values. - $config->setData($default_data); - - $variables = db_query("SELECT name, value FROM {variable} WHERE name like 'node_rank_%'")->fetchAllKeyed(); - if (!empty($variables)) { - foreach ($variables as $name => $value) { - // Trim node_rank_ - $rank = substr($name, 10); - $config->set('rank.' . $rank, unserialize($value)); - } - } - $config->save(); - } - - // Clean up any node_rank_ variables. - db_delete('variable')->condition('name', db_like('node_rank_') . '%', 'LIKE')->execute(); -} - -/** * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ 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 62e2102..836a828 100644 --- a/core/modules/system/tests/upgrade/drupal-7.system.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php @@ -164,20 +164,28 @@ '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_views', - 'value' => 'i:5;', + 'name' => 'node_rank_recent', + 'value' => 'i:2;', )) ->values(array( - 'name' => 'node_rank_comments', - 'value' => 'i:-2;', + 'name' => 'node_rank_relevance', + 'value' => 'i:8;', + )) + ->values(array( + 'name' => 'node_rank_sticky', + 'value' => 'i:3;', )) ->values(array( - 'name' => 'node_rank_custom', - 'value' => 'i:6;', + 'name' => 'node_rank_views', + 'value' => 'i:5;', )) ->execute(); 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 6b0ad23..9f77b0e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -168,6 +168,13 @@ public function testVariableUpgrade() { 'source.list_max' => 5, ); - $expected_config['search.plugin.node_search'] = array( - 'rank.promote' => 10, - 'rank.views' => 5, - 'rank.comments' => -2, - 'rank.custom' => 6, - ); - foreach ($expected_config as $file => $values) { $config = \Drupal::config($file); $this->verbose(print_r($config->get(), TRUE));