1 changed files with 0 additions and 42 deletions
@ -1,42 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
namespace Drupal\roblib_alter_solr; |
|
||||||
|
|
||||||
use Drupal\search_api\IndexInterface; |
|
||||||
use Drupal\search_api\Item\ItemInterface; |
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
||||||
use Drupal\search_api_solr\Event\SearchApiSolrEvents; |
|
||||||
|
|
||||||
/** |
|
||||||
* Provides a Solr document alter event subscriber. |
|
||||||
*/ |
|
||||||
class SolrDocumentAlterSubscriber implements EventSubscriberInterface { |
|
||||||
|
|
||||||
/** |
|
||||||
* {@inheritdoc} |
|
||||||
*/ |
|
||||||
public static function getSubscribedEvents(): array { |
|
||||||
return [ |
|
||||||
SearchApiSolrEvents::POST_CREATE_INDEX_DOCUMENT => 'alterSolrDocument', |
|
||||||
]; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Alters the Solr document before it is sent to Solr. |
|
||||||
* |
|
||||||
* @param \Drupal\search_api_solr\Event\SearchApiSolrEvents $event |
|
||||||
* The Solr document alter event. |
|
||||||
*/ |
|
||||||
public function alterSolrDocument(SearchApiSolrEvents $event) { |
|
||||||
$solrDocument = $event->getSolrDocument(); |
|
||||||
$item = $event->getItem(); |
|
||||||
$index = $event->getIndex(); |
|
||||||
|
|
||||||
if ($item->hasField('field_geo_area_name')) { |
|
||||||
$value = $item->getField('field_geo_area_name')->getValue(); |
|
||||||
$solrDocument->addField('dc.coverage', $value); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue