You are here

public function ContentAccess::preIndexSave in Search API 8

Preprocesses the search index entity before it is saved.

This can, for example, be used to make sure fields needed by this processor are enabled on the index.

Overrides ProcessorPluginBase::preIndexSave

File

src/Plugin/search_api/processor/ContentAccess.php, line 195

Class

ContentAccess
Adds content access checks for nodes and comments.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public function preIndexSave() {
  foreach ($this->index
    ->getDatasources() as $datasource_id => $datasource) {
    $entity_type = $datasource
      ->getEntityTypeId();
    if (in_array($entity_type, [
      'node',
      'comment',
    ])) {
      $this
        ->ensureField($datasource_id, 'status', 'boolean');
      if ($entity_type == 'node') {
        $this
          ->ensureField($datasource_id, 'uid', 'integer');
      }
    }
  }
  $field = $this
    ->ensureField(NULL, 'search_api_node_grants', 'string');
  $field
    ->setHidden();
}