diff --git a/README.txt b/README.txt index 1aba980..5c1bce0 100644 --- a/README.txt +++ b/README.txt @@ -21,9 +21,9 @@ numerous ways of extension the module provides. Hence, the growing number of additional contrib modules, providing additional functionality or helping users customize some aspects of the search process. * For a full description of the module, visit the project page: - https://www.drupal.org/project/search_api + https://drupal.org/project/search_api * To submit bug reports and feature suggestions, or to track changes: - https://www.drupal.org/project/issues/search_api + https://drupal.org/project/issues/search_api REQUIREMENTS ------------ @@ -32,7 +32,7 @@ No other modules required INSTALLATION ------------ * Install as you would normally install a contributed drupal module. See: - https://www.drupal.org/documentation/install/modules-themes/modules-8 + https://drupal.org/documentation/install/modules-themes/modules-7 for further information. CONFIGURATION @@ -50,4 +50,4 @@ Todo MAINTAINERS ----------- Current maintainers: - * Thomas Seidl (drunken monkey) - https://www.drupal.org/u/drunken-monkey + * Thomas Seidl (drunken monkey) - https://drupal.org/user/205582 diff --git a/search_api.views.inc b/search_api.views.inc index 2a1cb76..f053181 100644 --- a/search_api.views.inc +++ b/search_api.views.inc @@ -176,7 +176,7 @@ function _search_api_views_get_handlers(FieldInterface $field) { // @todo Detect fields with fixed lists of options, add type "options". $types[] = $field->getType(); /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type */ - $data_type = Utility::getDataTypePluginManager()->createInstance($field->getType()); + $data_type = \Drupal::service('plugin.manager.search_api.data_type')->createInstance($field->getType()); if (!$data_type->isDefault()) { $types[] = $data_type->getFallbackType(); } diff --git a/search_api_db/src/Plugin/search_api/backend/Database.php b/search_api_db/src/Plugin/search_api/backend/Database.php index c26c3c2..16ecef4 100644 --- a/search_api_db/src/Plugin/search_api/backend/Database.php +++ b/search_api_db/src/Plugin/search_api/backend/Database.php @@ -207,7 +207,7 @@ class Database extends BackendPluginBase { * The data type plugin manager. */ public function getDataTypePluginManager() { - return $this->dataTypePluginManager ?: Utility::getDataTypePluginManager(); + return $this->dataTypePluginManager ?: \Drupal::service('plugin.manager.search_api.data_type'); } /** diff --git a/src/DataType/DataTypePluginBase.php b/src/DataType/DataTypePluginBase.php index 78db30a..5fb07b2 100644 --- a/src/DataType/DataTypePluginBase.php +++ b/src/DataType/DataTypePluginBase.php @@ -9,7 +9,6 @@ namespace Drupal\search_api\DataType; use Drupal\Core\Plugin\PluginBase; use Drupal\search_api\Backend\BackendPluginManager; -use Drupal\search_api\Utility; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -74,7 +73,7 @@ abstract class DataTypePluginBase extends PluginBase implements DataTypeInterfac * The backend plugin manager. */ public function getBackendManager() { - return $this->backendManager ?: Utility::getBackendPluginManager(); + return $this->backendManager ?: \Drupal::service('plugin.manager.search_api.backend'); } /** diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 87844a9..24e7a5f 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -368,7 +368,8 @@ class Index extends ConfigEntityBase implements IndexInterface { public function getDatasources($only_enabled = TRUE) { if (!isset($this->datasourcePlugins)) { $this->datasourcePlugins = array(); - $datasource_plugin_manager = Utility::getDatasourcePluginManager(); + /** @var $datasource_plugin_manager \Drupal\search_api\Datasource\DatasourcePluginManager */ + $datasource_plugin_manager = \Drupal::service('plugin.manager.search_api.datasource'); foreach ($datasource_plugin_manager->getDefinitions() as $name => $datasource_definition) { if (class_exists($datasource_definition['class']) && empty($this->datasourcePlugins[$name])) { @@ -397,7 +398,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * {@inheritdoc} */ public function hasValidTracker() { - return (bool) Utility::getTrackerPluginManager()->getDefinition($this->getTrackerId(), FALSE); + return (bool) \Drupal::service('plugin.manager.search_api.tracker')->getDefinition($this->getTrackerId(), FALSE); } /** @@ -413,7 +414,7 @@ class Index extends ConfigEntityBase implements IndexInterface { public function getTracker() { if (!$this->trackerPlugin) { $tracker_plugin_configuration = array('index' => $this) + $this->tracker_config; - if (!($this->trackerPlugin = Utility::getTrackerPluginManager()->createInstance($this->getTrackerId(), $tracker_plugin_configuration))) { + if (!($this->trackerPlugin = \Drupal::service('plugin.manager.search_api.tracker')->createInstance($this->getTrackerId(), $tracker_plugin_configuration))) { $args['@tracker'] = $this->tracker; $args['%index'] = $this->label(); throw new SearchApiException(new FormattableMarkup('The tracker with ID "@tracker" could not be retrieved for index %index.', $args)); @@ -523,7 +524,8 @@ class Index extends ConfigEntityBase implements IndexInterface { */ protected function loadProcessors() { if (!isset($this->processors)) { - $processor_plugin_manager = Utility::getProcessorPluginManager(); + /** @var $processor_plugin_manager \Drupal\search_api\Processor\ProcessorPluginManager */ + $processor_plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $processor_settings = $this->getOption('processors', array()); foreach ($processor_plugin_manager->getDefinitions() as $name => $processor_definition) { diff --git a/src/Entity/Server.php b/src/Entity/Server.php index 3ed3db7..66cfaa7 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -112,7 +112,7 @@ class Server extends ConfigEntityBase implements ServerInterface { * {@inheritdoc} */ public function hasValidBackend() { - $backend_plugin_definition = Utility::getBackendPluginManager()->getDefinition($this->getBackendId(), FALSE); + $backend_plugin_definition = \Drupal::service('plugin.manager.search_api.backend')->getDefinition($this->getBackendId(), FALSE); return !empty($backend_plugin_definition); } @@ -128,7 +128,7 @@ class Server extends ConfigEntityBase implements ServerInterface { */ public function getBackend() { if (!$this->backendPlugin) { - $backend_plugin_manager = Utility::getBackendPluginManager(); + $backend_plugin_manager = \Drupal::service('plugin.manager.search_api.backend'); $config = $this->backend_config; $config['server'] = $this; if (!($this->backendPlugin = $backend_plugin_manager->createInstance($this->getBackendId(), $config))) { diff --git a/src/Form/IndexForm.php b/src/Form/IndexForm.php index 0b44eb6..a7bb1bd 100644 --- a/src/Form/IndexForm.php +++ b/src/Form/IndexForm.php @@ -97,7 +97,7 @@ class IndexForm extends EntityForm { * The datasource plugin manager. */ protected function getDatasourcePluginManager() { - return $this->datasourcePluginManager ?: Utility::getDatasourcePluginManager(); + return $this->datasourcePluginManager ?: \Drupal::service('plugin.manager.search_api.datasource'); } /** @@ -107,7 +107,7 @@ class IndexForm extends EntityForm { * The tracker plugin manager. */ protected function getTrackerPluginManager() { - return $this->trackerPluginManager ?: Utility::getTrackerPluginManager(); + return $this->trackerPluginManager ?: \Drupal::service('plugin.manager.search_api.tracker'); } /** diff --git a/src/Form/ServerForm.php b/src/Form/ServerForm.php index 5e1dd61..862da9e 100644 --- a/src/Form/ServerForm.php +++ b/src/Form/ServerForm.php @@ -15,7 +15,6 @@ use Drupal\Core\Url; use Drupal\search_api\Backend\BackendPluginManager; use Drupal\search_api\SearchApiException; use Drupal\search_api\ServerInterface; -use Drupal\search_api\Utility; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -78,7 +77,7 @@ class ServerForm extends EntityForm { * The backend plugin manager. */ protected function getBackendPluginManager() { - return $this->backendPluginManager ?: Utility::getBackendPluginManager(); + return $this->backendPluginManager ?: \Drupal::service('plugin.manager.search_api.backend'); } /** diff --git a/src/Plugin/views/filter/SearchApiFilterTrait.php b/src/Plugin/views/filter/SearchApiFilterTrait.php index 5e4e036..9b12f26 100644 --- a/src/Plugin/views/filter/SearchApiFilterTrait.php +++ b/src/Plugin/views/filter/SearchApiFilterTrait.php @@ -18,17 +18,17 @@ trait SearchApiFilterTrait { /** * Overrides the Views handlers' ensureMyTable() method. * - * This is done since this is not necessary for Search API queries. + * This is done since adding a table to a Search API query is neither + * necessary nor possible, but we still want to stay as compatible as possible + * to the default SQL query plugin. */ - public function ensureMyTable() { - // Do nothing. - } + public function ensureMyTable() {} /** * Adds a form for entering the value or values for the filter. * * Overridden to remove fields that won't be used (but aren't hidden either - * because of a small bug/glitch in the form code. + * because of a small bug/glitch in the original form code – see #2637674). * * @see \Drupal\views\Plugin\views\filter\FilterPluginBase::valueForm() */ @@ -72,11 +72,11 @@ trait SearchApiFilterTrait { // @todo Use "IN"/"NOT IN" instead, once available. $conjunction = $this->operator == 'or' ? 'OR' : 'AND'; $operator = $this->operator == 'not' ? '<>' : '='; - $filter = $this->getQuery()->createFilter($conjunction); + $filter = $this->getQuery()->createConditionGroup($conjunction); foreach ($this->value as $value) { - $filter->condition($this->realField, $value, $operator); + $filter->addCondition($this->realField, $value, $operator); } - $this->getQuery()->filter($filter, $this->options['group']); + $this->getQuery()->addConditionGroup($filter, $this->options['group']); } /** diff --git a/src/Plugin/views/query/SearchApiQuery.php b/src/Plugin/views/query/SearchApiQuery.php index 48bb88e..bb35837 100644 --- a/src/Plugin/views/query/SearchApiQuery.php +++ b/src/Plugin/views/query/SearchApiQuery.php @@ -766,14 +766,14 @@ class SearchApiQuery extends QueryPluginBase { if (is_object($field)) { if ($field instanceof ConditionInterface) { - $field = $this->transformConditionToFilter($field); + $field = $this->transformDbCondition($field); } if ($field instanceof ConditionGroupInterface) { $this->conditions[$group]['filters'][] = $field; } elseif (!$this->shouldAbort()) { - // We only need to abort if that wasn't done by - // transformConditionToFilter() already. + // We only need to abort if that wasn't done by transformDbCondition() + // already. $this->abort('Unexpected condition passed to addWhere().'); } } @@ -794,7 +794,7 @@ class SearchApiQuery extends QueryPluginBase { * A search filter equivalent to $condition, or NULL if the transformation * failed. */ - protected function transformConditionToFilter(ConditionInterface $db_condition) { + protected function transformDbCondition(ConditionInterface $db_condition) { $conditions = $db_condition->conditions(); $filter = $this->query->createConditionGroup($conditions['#conjunction']); unset($conditions['#conjunction']); @@ -804,7 +804,7 @@ class SearchApiQuery extends QueryPluginBase { return NULL; } if ($condition['field'] instanceof ConditionInterface) { - $nested_filter = $this->transformConditionToFilter($condition['field']); + $nested_filter = $this->transformDbCondition($condition['field']); if ($nested_filter) { $filter->addConditionGroup($nested_filter); } diff --git a/src/Tests/Processor/ProcessorTestBase.php b/src/Tests/Processor/ProcessorTestBase.php index 6f977be..64f9c22 100644 --- a/src/Tests/Processor/ProcessorTestBase.php +++ b/src/Tests/Processor/ProcessorTestBase.php @@ -109,7 +109,8 @@ abstract class ProcessorTestBase extends EntityUnitTestBase { ), )); - $plugin_manager = Utility::getProcessorPluginManager(); + /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */ + $plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index)); } $this->index->save(); diff --git a/src/Utility.php b/src/Utility.php index 89524b3..b5f75c6 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -158,7 +158,7 @@ class Utility { } static::$dataTypeFallbackMapping[$index_id] = array(); /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type */ - foreach (self::getDataTypePluginManager()->getInstances() as $type_id => $data_type) { + foreach (\Drupal::service('plugin.manager.search_api.data_type')->getInstances() as $type_id => $data_type) { // We know for sure that we do not need to fall back for the default // data types as they are always present and are required to be // supported by all backends. @@ -561,54 +561,4 @@ class Utility { return array(substr($combined_id, 0, $pos), substr($combined_id, $pos + 1)); } - /** - * Retrieves the plugin manager for Search API backend plugins. - * - * @return \Drupal\search_api\Backend\BackendPluginManager - * The backend plugin manager. - */ - public static function getBackendPluginManager() { - return \Drupal::service('plugin.manager.search_api.backend'); - } - - /** - * Retrieves the plugin manager for Search API data type plugins. - * - * @return \Drupal\search_api\DataType\DataTypePluginManager - * The data type plugin manager. - */ - public static function getDataTypePluginManager() { - return \Drupal::service('plugin.manager.search_api.data_type'); - } - - /** - * Retrieves the plugin manager for Search API datasource plugins. - * - * @return \Drupal\search_api\Datasource\DatasourcePluginManager - * The datasource plugin manager. - */ - public static function getDatasourcePluginManager() { - return \Drupal::service('plugin.manager.search_api.datasource'); - } - - /** - * Retrieves the plugin manager for Search API processor plugins. - * - * @return \Drupal\search_api\Processor\ProcessorPluginManager - * The processor plugin manager. - */ - public static function getProcessorPluginManager() { - return \Drupal::service('plugin.manager.search_api.processor'); - } - - /** - * Retrieves the plugin manager for Search API tracker plugins. - * - * @return \Drupal\search_api\Tracker\TrackerPluginManager - * The tracker plugin manager. - */ - public static function getTrackerPluginManager() { - return \Drupal::service('plugin.manager.search_api.tracker'); - } - }