You are here

protected function SearchApiFederatedSolrUrls::addDomainUrls in Search API Federated Solr 7

Same name and namespace in other branches
  1. 7.3 src/SearchApiFederatedSolrUrls.php \SearchApiFederatedSolrUrls::addDomainUrls()
  2. 7.2 src/SearchApiFederatedSolrUrls.php \SearchApiFederatedSolrUrls::addDomainUrls()
1 call to SearchApiFederatedSolrUrls::addDomainUrls()
SearchApiFederatedSolrUrls::alterItems in src/SearchApiFederatedSolrUrls.php
Alter items before indexing.

File

src/SearchApiFederatedSolrUrls.php, line 59

Class

SearchApiFederatedSolrUrls
Class SearchApiFederatedSolrUrls Provides a Search API index data alteration that adds the sites that the content is available on to each indexed item.

Code

protected function addDomainUrls(array &$items) {
  $entity_type = $this->index
    ->getEntityType();
  $entity_info = entity_get_info($entity_type);
  foreach ($items as $item) {
    $id = entity_id($entity_type, $item);

    // Get the entity object for the item being indexed, exit if there's somehow not one.
    $entity = current(entity_load($entity_type, [
      $id,
    ]));
    if (!$entity) {
      return;
    }
    $urls = domain_get_content_urls($entity);
    if (!empty($urls)) {
      $item->urls = $urls;
    }
    else {
      $list = [
        $item,
      ];
      $this
        ->addUrl($list);
    }
  }
}