You are here

protected function SearchApiFederatedSolrSiteName::addDomainName in Search API Federated Solr 7

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

File

src/SearchApiFederatedSolrSiteName.php, line 54

Class

SearchApiFederatedSolrSiteName
Class SearchApiFederatedSolrSiteName Provides a Search API index data alteration that adds a "Site Name" property to each indexed item.

Code

protected function addDomainName(array &$items) {
  $type = $this->index
    ->getEntityType();

  // Map the Domain of each node to its configured label.
  foreach ($items as &$item) {
    $nid = entity_id($type, $item);
    $entity = current(entity_load($type, [
      $nid,
    ]));
    $domains = domain_get_content_urls($entity);
    $ds = [];
    foreach ($domains as $domain_id => $url) {
      $domain = domain_lookup($domain_id);
      $ds[] = !empty($this->options['domain'][$domain['machine_name']]) ? $this->options['domain'][$domain['machine_name']] : $domain['sitename'];
    }
    $item->site_name = $ds;
  }
}