You are here

protected function FlaggingStorage::doDelete in Flag 8.4

Performs storage-specific entity deletion.

Parameters

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entity objects to delete.

Overrides ContentEntityStorageBase::doDelete

File

src/Entity/Storage/FlaggingStorage.php, line 164

Class

FlaggingStorage
Default SQL flagging storage.

Namespace

Drupal\flag\Entity\Storage

Code

protected function doDelete($entities) {
  parent::doDelete($entities);

  /** @var \Drupal\Core\Entity\ContentEntityInterface[] $entities */
  foreach ($entities as $entity) {

    // After deleting a flagging, remove it from the cached flagging by entity if already in static cache.
    if ($entity
      ->get('global')->value) {
      if (isset($this->globalFlagIdsByEntity[$entity
        ->get('entity_type')->value][$entity
        ->get('entity_id')->value][$entity
        ->get('flag_id')->value])) {
        unset($this->globalFlagIdsByEntity[$entity
          ->get('entity_type')->value][$entity
          ->get('entity_id')->value][$entity
          ->get('flag_id')->value]);
      }
    }
    else {
      if (isset($this->flagIdsByEntity[$entity
        ->get('uid')->target_id][$entity
        ->get('entity_type')->value][$entity
        ->get('entity_id')->value][$entity
        ->get('flag_id')->value])) {
        unset($this->flagIdsByEntity[$entity
          ->get('uid')->target_id][$entity
          ->get('entity_type')->value][$entity
          ->get('entity_id')->value][$entity
          ->get('flag_id')->value]);
      }
    }
  }
}