You are here

public function LanguageWithFallback::addFieldValues in Search API 8

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/LanguageWithFallback.php, line 130

Class

LanguageWithFallback
Adds the item's language (with fallbacks) to the indexed data.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {
  try {
    $entity = $item
      ->getOriginalObject()
      ->getValue();
  } catch (SearchApiException $e) {
    return;
  }
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  $langcodes = $this
    ->getReverseLanguageFallbacks($entity);
  $fields = $item
    ->getFields();
  $fields = $this
    ->getFieldsHelper()
    ->filterForPropertyPath($fields, NULL, 'language_with_fallback');
  foreach ($fields as $field) {
    foreach ($langcodes as $langcode) {
      $field
        ->addValue($langcode);
    }
  }
}