You are here

public function CommentStorage::delete in Multiversion 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Storage/Sql/CommentStorage.php \Drupal\multiversion\Entity\Storage\Sql\CommentStorage::delete()

Deletes permanently saved entities.

Parameters

array $entities: An array of entity objects to delete.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.

Overrides SqlContentEntityStorage::delete

File

src/Entity/Storage/Sql/CommentStorage.php, line 21

Class

CommentStorage
Storage handler for comments.

Namespace

Drupal\multiversion\Entity\Storage\Sql

Code

public function delete(array $entities) {

  // Ensure that the entities are keyed by ID.
  $keyed_entities = [];
  foreach ($entities as $entity) {
    $keyed_entities[$entity
      ->id()] = $entity;
  }

  // Delete received comments and all their children.
  if (!empty($keyed_entities)) {
    $child_cids = $this
      ->getChildCids($keyed_entities);
    while (!empty($child_cids)) {
      $child_entities = $this
        ->loadMultiple($child_cids);
      $keyed_entities = $keyed_entities + $child_entities;
      $child_cids = $this
        ->getChildCids($child_entities);
    }
  }

  // Sort the array with entities descending to delete children before their
  // parents.
  krsort($keyed_entities);
  $this
    ->deleteEntities($keyed_entities);
}