You are here

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

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/CanonicalUrl.php \Drupal\search_api_field_map\Plugin\search_api\processor\CanonicalUrl::addFieldValues()
  2. 4.x src/Plugin/search_api/processor/CanonicalUrl.php \Drupal\search_api_field_map\Plugin\search_api\processor\CanonicalUrl::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/CanonicalUrl.php, line 51

Class

CanonicalUrl
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_canonical_url');
  $use_source = FALSE;
  if ($this
    ->useDomainAccess()) {
    $entity = $item
      ->getOriginalObject()
      ->getValue();
    if ($entity instanceof EntityInterface) {
      $source = domain_source_get($entity);
    }
    if (empty($source)) {
      foreach ($fields as $field) {
        $field
          ->addValue('');
      }
      $use_source = TRUE;
    }
  }
  if (!$use_source) {
    $url = $item
      ->getDatasource()
      ->getItemUrl($item
      ->getOriginalObject());
    if ($url) {
      $url = $url
        ->setAbsolute()
        ->toString();
      foreach ($fields as $field) {
        $field
          ->addValue($url);
      }
    }
  }
}