Skip to content

Commit

Permalink
Replace deprecation for search_api. (#455)
Browse files Browse the repository at this point in the history
* Replace deprecation for search_api.

* fixup! Replace deprecation for search_api.

* Change constant to use strings.

* Remove deprecated hook.

---------

Co-authored-by: Mark Hanna <[email protected]>
  • Loading branch information
puresyntax71 and jackrabbithanna authored Aug 23, 2024
1 parent 2bfacc1 commit f58ed62
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
13 changes: 0 additions & 13 deletions civicrm_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\civicrm_entity\Plugin\search_api\datasource\CivicrmEntity as DatasourceCivicrmEntity;
use Drupal\Core\Field\Entity\BaseFieldOverride;

/**
Expand Down Expand Up @@ -751,18 +750,6 @@ function civicrm_entity_rules_action_info_alter(&$rules_actions) {
}
}

/**
* Implements hook_search_api_datasource_info_alter().
*/
function civicrm_entity_search_api_datasource_info_alter(array &$infos) {
foreach ($infos as $entity_type => &$info) {
if (strpos($entity_type, 'entity:civicrm_') !== FALSE) {
unset($info['deriver']);
$info['class'] = DatasourceCivicrmEntity::class;
}
}
}

/**
* Implements hook_civicrm_merge().
*/
Expand Down
5 changes: 5 additions & 0 deletions civicrm_entity.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ services:
arguments: ['@request_stack', '@civicrm_entity.api']
tags:
- {name: access_check, applies_to: _civicrm_entity_checksum_access_check }

civicrm_entity.search_api:
class: Drupal\civicrm_entity\EventSubscriber\SearchApiSubscriber
tags:
- { name: event_subscriber }
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

namespace Drupal\civicrm_entity\EventSubscriber;

use Drupal\search_api\Event\GatheringPluginInfoEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\civicrm_entity\Plugin\search_api\datasource\CivicrmEntity as DatasourceCivicrmEntity;

/**
* CiviCRM Entity event subscriber.
*/
class SearchApiSubscriber implements EventSubscriberInterface {

/**
* Gathering plugin info event handler.
*
* @param \Drupal\search_api\Event\GatheringPluginInfoEvent $event
* Gathering info event.
*/
public function onGatheringDataSources(GatheringPluginInfoEvent $event) {
foreach ($event->getDefinitions() as $entity_type => &$definition) {
if (strpos($entity_type, 'entity:civicrm_') !== FALSE) {
unset($definition['deriver']);
$definition['class'] = DatasourceCivicrmEntity::class;
}
}
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
'search_api.gathering_data_sources' => ['onGatheringDataSources'],
];
}

}

0 comments on commit f58ed62

Please sign in to comment.