You are here

public function EntityUsageBase::trackOnEntityDelete in Entity Usage 8.4

File

src/EntityUsageBase.php, line 169

Class

EntityUsageBase
Base implementation for track plugins.

Namespace

Drupal\entity_usage

Code

public function trackOnEntityDelete(EntityInterface $source_entity, $type) {

  // When an entity is being deleted the logic is much simpler and we just
  // delete the records that affect this entity both as target and source.
  switch ($type) {
    case 'revision':
      $this->usageService
        ->deleteBySourceEntity($source_entity
        ->id(), $source_entity
        ->getEntityTypeId(), NULL, $source_entity
        ->getRevisionId());
      break;
    case 'translation':
      $this->usageService
        ->deleteBySourceEntity($source_entity
        ->id(), $source_entity
        ->getEntityTypeId(), $source_entity
        ->language()
        ->getId());
      break;
    case 'default':
      $this->usageService
        ->deleteBySourceEntity($source_entity
        ->id(), $source_entity
        ->getEntityTypeId());
      $this->usageService
        ->deleteByTargetEntity($source_entity
        ->id(), $source_entity
        ->getEntityTypeId());
      break;
  }
}