public static function Server::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/ Server.php, line 548
Class
- Server
- Defines the search server configuration entity.
Namespace
Drupal\search_api\EntityCode
public static function preDelete(EntityStorageInterface $storage, array $entities) {
// @todo This will, via Index::onDependencyRemoval(), remove all indexes
// from this server, triggering the server's removeIndex() method. This
// is, at best, wasted performance and could at worst lead to a bug if
// removeIndex() saves the server. We should try what happens when this is
// the case, whether there really is a bug, and try to fix it somehow –
// maybe clever detection of this case in removeIndex() or
// Index::postSave(). $server->isUninstalling() might help?
parent::preDelete($storage, $entities);
// Iterate through the servers, executing the backends' preDelete() methods
// and removing all their pending server tasks.
foreach ($entities as $server) {
/** @var \Drupal\search_api\ServerInterface $server */
if ($server
->hasValidBackend()) {
$server
->getBackend()
->preDelete();
}
\Drupal::getContainer()
->get('search_api.server_task_manager')
->delete($server);
}
}