You are here

public static function Index::preDelete in Search API 8

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides ConfigEntityBase::preDelete

File

src/Entity/Index.php, line 1573

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {
  parent::preDelete($storage, $entities);
  $index_task_manager = \Drupal::getContainer()
    ->get('search_api.index_task_manager');

  /** @var \Drupal\search_api\IndexInterface[] $entities */
  foreach ($entities as $index) {
    if ($index
      ->status()) {
      $index_task_manager
        ->stopTracking($index);
      if ($index
        ->hasValidServer()) {
        $index
          ->getServerInstance()
          ->removeIndex($index);
      }
    }
  }
}