protected function SearchApiDisplay::getQueryTypesForDataType in Facets 8
Retrieves the query types for a specified data type.
Backend plugins can use this method to override the default query types provided by the Search API with backend-specific ones that better use features of that backend.
Parameters
\Drupal\search_api\Backend\BackendInterface $backend: The backend that we want to get the query types for.
string $data_type_plugin_id: The identifier of the data type.
Return value
string[] An associative array with the plugin IDs of allowed query types, keyed by the generic name of the query_type.
See also
hook_facets_search_api_query_type_mapping_alter()
2 calls to SearchApiDisplay::getQueryTypesForDataType()
- SearchApiDisplay::getFields in src/
Plugin/ facets/ facet_source/ SearchApiDisplay.php - Returns an array of fields that are defined on the facet source.
- SearchApiDisplay::getQueryTypesForFacet in src/
Plugin/ facets/ facet_source/ SearchApiDisplay.php - Returns the allowed query types for a given facet for the facet source.
File
- src/
Plugin/ facets/ facet_source/ SearchApiDisplay.php, line 287
Class
- SearchApiDisplay
- Provides a facet source based on a Search API display.
Namespace
Drupal\facets\Plugin\facets\facet_sourceCode
protected function getQueryTypesForDataType(BackendInterface $backend, $data_type_plugin_id) {
$query_types = [];
$query_types['string'] = 'search_api_string';
// Add additional query types for specific data types.
switch ($data_type_plugin_id) {
case 'date':
$query_types['date'] = 'search_api_date';
$query_types['range'] = 'search_api_range';
break;
case 'decimal':
case 'integer':
$query_types['numeric'] = 'search_api_granular';
$query_types['range'] = 'search_api_range';
break;
}
// Find out if the backend implemented the Interface to retrieve specific
// query types for the supported data_types.
if ($backend instanceof FacetsQueryTypeMappingInterface) {
$mapping = [
$data_type_plugin_id => &$query_types,
];
$backend
->alterFacetQueryTypeMapping($mapping);
}
// Add it to a variable so we can pass it by reference. Alter hook complains
// due to the property of the backend object is not passable by reference.
$backend_plugin_id = $backend
->getPluginId();
// Let modules alter this mapping.
\Drupal::moduleHandler()
->alter('facets_search_api_query_type_mapping', $backend_plugin_id, $query_types);
return $query_types;
}