Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UHF-10774: Map searchapi types
Browse files Browse the repository at this point in the history
hyrsky committed Nov 12, 2024
1 parent eb35beb commit 51850cf
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions helfi_platform_config.services.yml
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@ services:
class: Drupal\helfi_platform_config\EventSubscriber\RouteSubscriber
arguments: ['@current_route_match']

Drupal\helfi_platform_config\EventSubscriber\SearchApiSubscriber:
class: Drupal\helfi_platform_config\EventSubscriber\SearchApiSubscriber
arguments: []

Drupal\helfi_platform_config\EntityVersionMatcher: '@helfi_platform_config.entity_version_matcher'
helfi_platform_config.entity_version_matcher:
class: Drupal\helfi_platform_config\EntityVersionMatcher
38 changes: 38 additions & 0 deletions src/EventSubscriber/SearchApiSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_platform_config\EventSubscriber;

use Drupal\search_api\Event\MappingFieldTypesEvent;
use Drupal\search_api\Event\SearchApiEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Search api event subscriber.
*/
final class SearchApiSubscriber implements EventSubscriberInterface {

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
// Bail if search_api is not installed.
if (!class_exists(SearchApiEvents::class)) {
return [];
}

return [
SearchApiEvents::MAPPING_FIELD_TYPES => 'mapFieldTypes',
];
}

/**
* Map custom field types.
*/
public function mapFieldTypes(MappingFieldTypesEvent $event): void {
$mapping = &$event->getFieldTypeMapping();
$mapping['location'] = 'location';
}

}
2 changes: 2 additions & 0 deletions src/Plugin/search_api/data_type/LocationDataType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_platform_config\Plugin\search_api\data_type;

use Drupal\search_api\DataType\DataTypePluginBase;

0 comments on commit 51850cf

Please sign in to comment.