You are here

public function Urls::addFieldValues in Search API Field Map 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls::addFieldValues()
  2. 8.2 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls::addFieldValues()
  3. 4.x src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls::addFieldValues()

Adds the values of properties defined by this processor to the item.

Parameters

\Drupal\search_api\Item\ItemInterface $item: The item whose field values should be added.

Overrides ProcessorPluginBase::addFieldValues

File

src/Plugin/search_api/processor/Urls.php, line 51

Class

Urls
Adds the Urls to the indexed data.

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {
  $fields = $this
    ->getFieldsHelper()
    ->filterForPropertyPath($item
    ->getFields(), NULL, 'search_api_urls');
  $use_domain = FALSE;
  if ($this
    ->useDomainAccess()) {
    $entity = $item
      ->getOriginalObject()
      ->getValue();
    if ($entity instanceof EntityInterface) {
      $manager = \Drupal::service('domain_access.manager');
      $urls = $manager
        ->getContentUrls($entity);
      if (!empty($urls)) {
        foreach ($fields as $field) {
          foreach ($urls as $url) {
            $field
              ->addValue($url);
          }
        }
        $use_domain = TRUE;
      }
    }
  }
  if (!$use_domain) {
    $url = $item
      ->getDatasource()
      ->getItemUrl($item
      ->getOriginalObject());
    if ($url) {
      $urls = [
        $url
          ->setAbsolute()
          ->toString(),
      ];
      foreach ($fields as $field) {
        $field
          ->addValue($urls);
      }
    }
  }
}