-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt rolling additional tracking.
... didn't seem to work.
- Loading branch information
1 parent
a4a8d3e
commit 01b77bb
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\EventSubscriber; | ||
|
||
use Drupal\search_api\Event\MappingForeignRelationshipsEvent; | ||
use Drupal\search_api\Event\SearchApiEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Inform search_api of entity_reference structures. | ||
*/ | ||
class TrackingEventSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() : array { | ||
return [ | ||
SearchApiEvents::MAPPING_FOREIGN_RELATIONSHIPS => 'foreignRelationshipMap', | ||
]; | ||
} | ||
|
||
/** | ||
* Inform search_api of our computed entity_reference listings. | ||
* | ||
* @param \Drupal\search_api\Event\MappingForeignRelationshipsEvent $event | ||
* The event by which to inform. | ||
*/ | ||
public function foreignRelationshipMap(MappingForeignRelationshipsEvent $event) : void { | ||
$mapping =& $event->getForeignRelationshipsMapping(); | ||
$index = $event->getIndex(); | ||
foreach ($index->getDatasources() as $id => $datasource) { | ||
if (!in_array($datasource->getEntityTypeId(), ['file', 'media', 'node'])) { | ||
continue; | ||
} | ||
|
||
$mapping[] = [ | ||
'datasource' => $id, | ||
'entity_type' => 'embargo', | ||
'property_path_to_foreign_entity' => 'embargo:entity:id', | ||
'field_name' => 'id', | ||
]; | ||
} | ||
} | ||
|
||
} |