You are here

public function SearchExcludeNodeSearch::reIndex in Search Exclude (Node) 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Search/SearchExcludeNodeSearch.php \Drupal\search_exclude\Plugin\Search\SearchExcludeNodeSearch::reIndex()
  2. 2.0.x src/Plugin/Search/SearchExcludeNodeSearch.php \Drupal\search_exclude\Plugin\Search\SearchExcludeNodeSearch::reIndex()

Check if the entity needs to be re-indexed.

If the $entity is a comment, the reindexing will aply to the associated node, otherwise the node itself. This will trigger a re-indexing only if the node type is not configured to be excluded by this plugin.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Either a node or a comments entity.

File

src/Plugin/Search/SearchExcludeNodeSearch.php, line 153

Class

SearchExcludeNodeSearch
Search plugin to exclude node bundles from the Search module index.

Namespace

Drupal\search_exclude\Plugin\Search

Code

public function reIndex(EntityInterface $entity) {
  if ($entity instanceof CommentInterface) {
    if ($entity
      ->getCommentedEntityTypeId() !== 'node') {
      return;
    }
    $node = $entity
      ->getCommentedEntity();
  }
  else {
    if ($entity instanceof NodeInterface) {
      $node = $entity;
    }
    else {
      return;
    }
  }

  /** @var \Drupal\node\NodeInterface $node */
  if (in_array($node
    ->getType(), $this->configuration['excluded_bundles'])) {
    return;
  }
  search_mark_for_reindex('search_exclude_node_search', $node
    ->id());
}