You are here

protected function SearchApiFederatedSolrCanonicalUrl::addDomainUrl in Search API Federated Solr 7.3

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

File

src/SearchApiFederatedSolrCanonicalUrl.php, line 59

Class

SearchApiFederatedSolrCanonicalUrl
Class SearchApiFederatedSolrCanonicalUrl Provides a Search API index data alteration that indicates the preferred URL content is available on to each indexed item.

Code

protected function addDomainUrl(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;
    }

    // Determine if there is a canonical URL for the content.
    // This only comes into play if domain source is used.
    if (isset($entity->domain_source) && $entity->domain_source == DOMAIN_SOURCE_USE_ACTIVE) {
      $this->canonical_url = '';
    }
    else {
      $list = [
        $item,
      ];
      $this
        ->addUrl($list);
    }
  }
}