You are here

public function EntityStatus::alterIndexedItems in Search API 8

Alter the items to be indexed.

Parameters

\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be indexed, passed by reference.

Overrides ProcessorPluginBase::alterIndexedItems

File

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

Class

EntityStatus
Excludes unpublished nodes from node indexes.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public function alterIndexedItems(array &$items) {

  // Annoyingly, this doc comment is needed for PHPStorm. See
  // http://youtrack.jetbrains.com/issue/WI-23586

  /** @var \Drupal\search_api\Item\ItemInterface $item */
  foreach ($items as $item_id => $item) {
    $object = $item
      ->getOriginalObject()
      ->getValue();
    $enabled = TRUE;
    if ($object instanceof EntityPublishedInterface) {
      $enabled = $object
        ->isPublished();
    }
    elseif ($object instanceof UserInterface) {
      $enabled = $object
        ->isActive();
    }
    if (!$enabled) {
      unset($items[$item_id]);
    }
  }
}