You are here

protected function SiteName::addDomainName in Search API Field Map 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/processor/SiteName.php \Drupal\search_api_field_map\Plugin\search_api\processor\SiteName::addDomainName()
  2. 4.x src/Plugin/search_api/processor/SiteName.php \Drupal\search_api_field_map\Plugin\search_api\processor\SiteName::addDomainName()

Process site names for Domains.

@TODO: Allow this value to be configured.

Parameters

Drupal\search_api\Item\ItemInterface $item: The item being indexed.

Drupal\Core\Entity\EntityInterface $entity: The original entity of the item.

array $fields: The fields being processed for this item.

1 call to SiteName::addDomainName()
SiteName::addFieldValues in src/Plugin/search_api/processor/SiteName.php
Adds the values of properties defined by this processor to the item.

File

src/Plugin/search_api/processor/SiteName.php, line 90

Class

SiteName
Adds the site name to the indexed data.

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor

Code

protected function addDomainName(ItemInterface $item, EntityInterface $entity, array $fields) {
  $manager = \Drupal::service('domain_access.manager');
  $urls = $manager
    ->getContentUrls($entity);
  if (!empty($urls)) {
    $storage = \Drupal::service('entity_type.manager')
      ->getStorage('domain');
    $domains = $storage
      ->loadMultiple();
    foreach ($fields as $field) {
      foreach ($urls as $domain_id => $url) {
        if (isset($domains[$domain_id])) {
          $site_name = !empty($field
            ->getConfiguration()['domain'][$domains[$domain_id]
            ->id()]) ? $field
            ->getConfiguration()['domain'][$domains[$domain_id]
            ->id()] : $domains[$domain_id]
            ->label();
        }
        else {
          $site_name = $field
            ->getConfiguration()['site_name'];
        }
        if (empty($site_name)) {
          $site_name = \Drupal::config('system.site')
            ->get('name');
        }
        $field
          ->addValue($site_name);
      }
    }
  }
  else {
    foreach ($fields as $field) {
      $site_name = $field
        ->getConfiguration()['site_name'];
      if (empty($site_name)) {
        $site_name = \Drupal::config('system.site')
          ->get('name');
      }
      $field
        ->addValue($site_name);
    }
  }
}