You are here

public static function EntityStatus::supportsIndex in Search API 8

Checks whether this processor is applicable for a certain index.

This can be used for hiding the processor on the index's "Filters" tab. To avoid confusion, you should only use criteria that are more or less constant, such as the index's datasources. Also, since this is only used for UI purposes, you should not completely rely on this to ensure certain index configurations and at least throw an exception with a descriptive error message if this is violated on runtime.

Parameters

\Drupal\search_api\IndexInterface $index: The index to check for.

Return value

bool TRUE if the processor can run on the given index; FALSE otherwise.

Overrides ProcessorPluginBase::supportsIndex

1 call to EntityStatus::supportsIndex()
EntityStatusTest::testSupportsIndex in tests/src/Unit/Processor/EntityStatusTest.php
Tests whether supportsIndex() returns TRUE for an index containing nodes.

File

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

Class

EntityStatus
Excludes unpublished nodes from node indexes.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public static function supportsIndex(IndexInterface $index) {
  $interface = EntityPublishedInterface::class;
  foreach ($index
    ->getDatasources() as $datasource) {
    $entity_type_id = $datasource
      ->getEntityTypeId();
    if (!$entity_type_id) {
      continue;
    }

    // We support users and any entities that implement
    // \Drupal\Core\Entity\EntityPublishedInterface.
    if ($entity_type_id === 'user') {
      return TRUE;
    }
    $entity_type = \Drupal::entityTypeManager()
      ->getDefinition($entity_type_id);
    if ($entity_type && $entity_type
      ->entityClassImplements($interface)) {
      return TRUE;
    }
  }
  return FALSE;
}