public function DataTypeHelper::getFieldTypeMapping in Search API 8
Retrieves the mapping for known data types to Search API's internal types.
Return value
string[] An array mapping all known (and supported) Drupal data types to their corresponding Search API data types. Empty values mean that fields of that type should be ignored by the Search API.
Overrides DataTypeHelperInterface::getFieldTypeMapping
See also
hook_search_api_field_type_mapping_alter()
File
- src/
Utility/ DataTypeHelper.php, line 90
Class
- DataTypeHelper
- Provides helper methods for dealing with Search API data types.
Namespace
Drupal\search_api\UtilityCode
public function getFieldTypeMapping() {
// Check the cache first.
if (!isset($this->fieldTypeMapping)) {
// It's easier to write and understand this array in the form of
// $searchApiFieldType => [$dataTypes] and flip it below.
$defaultMapping = [
'text' => [
'field_item:string_long.string',
'field_item:text_long.string',
'field_item:text_with_summary.string',
'search_api_html',
'search_api_text',
],
'string' => [
'string',
'email',
'uri',
'filter_format',
'duration_iso8601',
'field_item:path',
],
'integer' => [
'integer',
'timespan',
],
'decimal' => [
'decimal',
'float',
],
'date' => [
'date',
'datetime_iso8601',
'timestamp',
],
'boolean' => [
'boolean',
],
// Types we know about but want/have to ignore.
NULL => [
'language',
],
];
foreach ($defaultMapping as $searchApiType => $dataTypes) {
foreach ($dataTypes as $dataType) {
$mapping[$dataType] = $searchApiType;
}
}
// Allow other modules to intercept and define what default type they want
// to use for their data type.
$description = 'This hook is deprecated in search_api:8.x-1.14 and is removed from search_api:2.0.0. Please use the "search_api.mapping_field_types" event instead. See https://www.drupal.org/node/3059866';
$hook = 'search_api_field_type_mapping';
$this->moduleHandler
->alterDeprecated($description, $hook, $mapping);
$eventName = SearchApiEvents::MAPPING_FIELD_TYPES;
$event = new MappingFieldTypesEvent($mapping);
$this->eventDispatcher
->dispatch($eventName, $event);
$this->fieldTypeMapping = $mapping;
}
return $this->fieldTypeMapping;
}