diff --git a/search_api_solr.module b/search_api_solr.module index 9e24bb23..8d419cdc 100644 --- a/search_api_solr.module +++ b/search_api_solr.module @@ -551,35 +551,6 @@ function search_api_solr_form_search_api_index_form_validate_server(&$element, F } } -/** - * Implements hook_search_api_views_handler_mapping_alter() - * - * @param array $mapping - * An associative array with data types as the keys and Views field data - * definitions as the values. In addition to all normally defined data types, - * keys can also be "options" for any field with an options list, "entity" for - * general entity-typed fields or "entity:ENTITY_TYPE" (with "ENTITY_TYPE" - * being the machine name of an entity type) for entities of that type. - * - * @see _search_api_views_handler_mapping() - */ -function search_api_solr_search_api_views_handler_mapping_alter(&$mapping) { - $mapping['solr_text_omit_norms'] = - $mapping['solr_text_suggester'] = - $mapping['solr_text_unstemmed'] = - $mapping['solr_text_wstoken'] = [ - 'argument' => [ - 'id' => 'search_api', - ], - 'filter' => [ - 'id' => 'search_api_fulltext', - ], - 'sort' => [ - 'id' => 'search_api', - ], - ]; -} - /** * Implements hook_views_data_alter(). * diff --git a/search_api_solr.services.yml b/search_api_solr.services.yml index 80484618..5263db33 100644 --- a/search_api_solr.services.yml +++ b/search_api_solr.services.yml @@ -9,6 +9,12 @@ services: tags: - {name: event_subscriber} + search_api_solr.search_api_subscriber: + class: Drupal\search_api_solr\EventSubscriber\SearchApiSubscriber + arguments: [] + tags: + - { name: event_subscriber } + search_api_solr.local_action_access_check: class: Drupal\search_api_solr\Access\LocalActionAccessCheck arguments: ['@current_user'] diff --git a/src/EventSubscriber/SearchApiSubscriber.php b/src/EventSubscriber/SearchApiSubscriber.php new file mode 100644 index 00000000..ac3a5fea --- /dev/null +++ b/src/EventSubscriber/SearchApiSubscriber.php @@ -0,0 +1,62 @@ + [ + 'id' => 'search_api', + ], + 'filter' => [ + 'id' => 'search_api_fulltext', + ], + 'sort' => [ + 'id' => 'search_api', + ], + ]; + } + + /** + * Subscribed events getter. + */ + public static function getSubscribedEvents() { + // Workaround to avoid a fatal error during site install in some cases. + // @see https://www.drupal.org/project/facets/issues/3199156 + if (!class_exists('\Drupal\search_api\Event\SearchApiEvents', TRUE)) { + return []; + } + + return [ + SearchApiEvents::MAPPING_VIEWS_FIELD_HANDLERS => 'onMappingViewsFiledHandlers', + ]; + + } + +}