diff --git a/search_api.views.inc b/search_api.views.inc index 757b4d9..2a1cb76 100644 --- a/search_api.views.inc +++ b/search_api.views.inc @@ -55,6 +55,7 @@ function search_api_views_data() { if (isset($table['search_api_language']['filter']['id'])) { $table['search_api_language']['filter']['id'] = 'search_api_language'; + $table['search_api_language']['filter']['allow empty'] = FALSE; } // Add handlers for special fields. @@ -175,15 +176,14 @@ 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 = Utility::getDataTypePluginManager()->createInstance($field->getType()); if (!$data_type->isDefault()) { $types[] = $data_type->getFallbackType(); } foreach ($types as $type) { if (isset($mapping[$type])) { - _search_api_views_handler_adjustments($type, $field, $mapping); + _search_api_views_handler_adjustments($type, $field, $mapping[$type]); return $mapping[$type]; } } @@ -204,19 +204,24 @@ function _search_api_views_get_handlers(FieldInterface $field) { * The type of field, as defined in _search_api_views_handler_mapping(). * @param \Drupal\search_api\Item\FieldInterface $field * The field whose handler definitions are being created. - * @param array $mapping + * @param array $definitions * The handler definitions for the field, as a reference. */ -function _search_api_views_handler_adjustments($type, FieldInterface $field, array &$mapping) { - $definition = $field->getDataDefinition(); +function _search_api_views_handler_adjustments($type, FieldInterface $field, array &$definitions) { + $data_definition = $field->getDataDefinition(); if ($type == 'entity:taxonomy_term') { - if (isset($definition->getSettings()['handler_settings']['target_bundles'])) { - $target_bundles = $definition->getSettings()['handler_settings']['target_bundles']; + if (isset($data_definition->getSettings()['handler_settings']['target_bundles'])) { + $target_bundles = $data_definition->getSettings()['handler_settings']['target_bundles']; if (count($target_bundles) == 1) { - $mapping[$type]['vocabulary'] = reset($target_bundles); + $definitions['filter']['vocabulary'] = reset($target_bundles); } } } + // By default, all fields can be empty (or at least have to be treated that + // way by the Search API). + if (!isset($definitions['filter']['allow empty'])) { + $definitions['filter']['allow empty'] = TRUE; + } } /** diff --git a/src/Plugin/views/filter/SearchApiFilterTrait.php b/src/Plugin/views/filter/SearchApiFilterTrait.php index cb62d5a..5e4e036 100644 --- a/src/Plugin/views/filter/SearchApiFilterTrait.php +++ b/src/Plugin/views/filter/SearchApiFilterTrait.php @@ -1,4 +1,5 @@ definition['allow empty'])) { - $this->definition['allow empty'] = TRUE; - } - } - - /** * Overrides the Views handlers' ensureMyTable() method. * * This is done since this is not necessary for Search API queries.