You are here

public function FlagIndexer::addFieldValues in Flag 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/FlagIndexer.php, line 155

Class

FlagIndexer
Search API Processor for indexing flags.

Namespace

Drupal\flag_search_api\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {
  $config = $this->configuration['flag_index'];
  $flags = $this->flagService
    ->getAllFlags();
  try {
    $entity = $item
      ->getOriginalObject()
      ->getValue();
    foreach ($config as $flag_id) {
      $fields = $this
        ->getFieldsHelper()
        ->filterForPropertyPath($item
        ->getFields(), NULL, 'flag_' . $flag_id);
      foreach ($fields as $flag_field) {
        $users = $this->flagService
          ->getFlaggingUsers($entity, $flags[$flag_id]);

        /** @var \Drupal\user\Entity\User $user */
        foreach ($users as $user) {
          $flag_field
            ->addValue($user
            ->id());
        }
      }
    }
  } catch (SearchApiException $exception) {
    $this->logger
      ->error($exception
      ->getMessage());
  }
}