diff -u b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php --- b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -8,7 +8,6 @@ namespace Drupal\node\Plugin\Search; use Drupal\Core\Annotation\Translation; -use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Entity\EntityInterface; @@ -58,13 +57,6 @@ protected $moduleHandler; /** - * The configuration factory. - * - * @var \Drupal\Core\Config\ConfigFactory - */ - protected $configFactory; - - /** * The Drupal state object used to set 'node.cron_last'. * * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface @@ -109,7 +101,6 @@ $container->get('database'), $container->get('plugin.manager.entity'), $container->get('module_handler'), - $container->get('config.factory'), $container->get('keyvalue')->get('state'), $container->get('request')->attributes->get('_account') ); @@ -130,18 +121,15 @@ * An entity manager object. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * A module manager object. - * @param \Drupal\Core\Config\ConfigFactory $config_factory - * The configuration factory. * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state * The Drupal state object used to set 'node.cron_last'. * @param \Drupal\Core\Session\AccountInterface $account * The $account object to use for checking for access to advanced search. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $database, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, ConfigFactory $config_factory, KeyValueStoreInterface $state, AccountInterface $account = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $database, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, KeyValueStoreInterface $state, AccountInterface $account = NULL) { $this->database = $database; $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; - $this->configFactory = $config_factory; $this->state = $state; $this->account = $account; parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -271,13 +259,14 @@ if ($ranking = $this->moduleHandler->invokeAll('ranking')) { $tables = &$query->getTables(); foreach ($ranking as $rank => $values) { - if (!empty($this->configuration['rank'][$rank])) { + $rank = $this->configuration['search.plugin.' . $this->pluginId]->get('rank.' . $rank); + if (!empty($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']); } $arguments = isset($values['arguments']) ? $values['arguments'] : array(); - $query->addScore($values['score'], $arguments, $this->configuration['rank'][$rank]); + $query->addScore($values['score'], $arguments, $rank); } } } @@ -287,7 +276,7 @@ * {@inheritdoc} */ public function updateIndex() { - $limit = (int) $this->configFactory->get('search.settings')->get('index.cron_limit'); + $limit = (int) $this->configuration['search.settings']->get('index.cron_limit'); $result = $this->database->queryRange("SELECT DISTINCT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = :type AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(':type' => $this->getPluginId()), array('target' => 'slave')); $nids = $result->fetchCol(); @@ -529,11 +518,12 @@ // Note: reversed to reflect that higher number = higher ranking. $options = drupal_map_assoc(range(0, 10)); foreach ($this->moduleHandler->invokeAll('ranking') as $var => $values) { + $rank = $this->configuration['search.plugin.' . $this->pluginId]->get('rank.' . $var); $form['content_ranking']['factors']['node_rank_' . $var] = array( '#title' => $values['title'], '#type' => 'select', '#options' => $options, - '#default_value' => isset($this->configuration['rank'][$var]) ? $this->configuration['rank'][$var] : 0, + '#default_value' => isset($rank) ? $rank : 0, ); } } @@ -542,7 +532,7 @@ * {@inheritdoc} */ public function submitAdminForm(array &$form, array &$form_state) { - $config = $this->configFactory->get('search.plugin.' . $this->pluginId); + $config = $this->configuration['search.plugin.' . $this->pluginId]; 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]); diff -u b/core/modules/search/lib/Drupal/search/SearchPluginManager.php b/core/modules/search/lib/Drupal/search/SearchPluginManager.php --- b/core/modules/search/lib/Drupal/search/SearchPluginManager.php +++ b/core/modules/search/lib/Drupal/search/SearchPluginManager.php @@ -129,20 +129,16 @@ /** * Gets plugin configuration stored in the configuration management system. * - * @param $plugin_id + * @param string $plugin_id * The id of the plugin to get configuration for. * * @return array * An array of plugin configuration. */ protected function getConfiguration($plugin_id) { - $configuration = $this->configFactory->get('search.plugin.' . $plugin_id)->get(); - - // Ensure we return an array. If the plugin has no configuration this will - // be null. - if (!is_array($configuration)) { - $configuration = array(); - } + $configuration = array(); + $configuration['search.plugin.' . $plugin_id] = $this->configFactory->get('search.plugin.' . $plugin_id); + $configuration['search.settings'] = $this->configFactory->get('search.settings'); return $configuration; } only in patch2: unchanged: --- a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a base class for plugins wishing to support search. @@ -39,6 +40,17 @@ /** * {@inheritdoc} */ + static public function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition + ); + } + + /** + * {@inheritdoc} + */ public function setSearch($keywords, array $parameters, array $attributes) { $this->keywords = (string) $keywords; $this->searchParameters = $parameters; only in patch2: unchanged: --- a/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php +++ b/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php @@ -25,40 +25,6 @@ class SearchExtraTypeSearch extends SearchPluginBase { /** - * @var \Drupal\Core\Config\Config - */ - protected $configSettings; - - /** - * {@inheritdoc} - */ - static public function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { - return new static( - $container->get('config.factory')->get('search_extra_type.settings'), - $configuration, - $plugin_id, - $plugin_definition - ); - } - - /** - * Creates a SearchExtraTypeSearch object. - * - * @param Config $config_settings - * The extra config settings. - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param array $plugin_definition - * The plugin implementation definition. - */ - public function __construct(Config $config_settings, array $configuration, $plugin_id, array $plugin_definition) { - $this->configSettings = $config_settings; - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - - /** * {@inheritdoc} */ public function setSearch($keywords, array $parameters, array $attributes) { @@ -139,7 +105,7 @@ public function addToAdminForm(array &$form, array &$form_state) { 'bi' => t('Bistromathic'), 'ii' => t('Infinite Improbability'), ), - '#default_value' => $this->configSettings->get('boost'), + '#default_value' => $this->configuration['search.plugin.' . $this->pluginId]->get('boost'), ); } @@ -147,7 +113,7 @@ public function addToAdminForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitAdminForm(array &$form, array &$form_state) { - $this->configSettings + $this->configuration['search.plugin.' . $this->pluginId] ->set('boost', $form_state['values']['extra_type_settings']['boost']) ->save(); }