You are here

protected function EntityUpdateManager::trackUpdateOnDeletion in Entity Usage 8.3

Same name and namespace in other branches
  1. 8 src/EntityUpdateManager.php \Drupal\entity_usage\EntityUpdateManager::trackUpdateOnDeletion()
  2. 8.2 src/EntityUpdateManager.php \Drupal\entity_usage\EntityUpdateManager::trackUpdateOnDeletion()

Track updates on deletion of entities.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity we are dealing with.

string $type: What type of deletion is being performed:

  • default: The main entity (default language, default revision) is being

deleted (delete also other languages and revisions).

  • translation: Only one translation is being deleted.
  • revision: Onlyone revision is being deleted.

Throws

\InvalidArgumentException

1 call to EntityUpdateManager::trackUpdateOnDeletion()
EntityUpdateManager::destruct in src/EntityUpdateManager.php
Performs destruct operations.

File

src/EntityUpdateManager.php, line 259

Class

EntityUpdateManager
Class EntityUpdateManager.

Namespace

Drupal\entity_usage

Code

protected function trackUpdateOnDeletion(EntityInterface $entity, $type = 'default') {

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

      // We only accept one of the above mentioned types.
      throw new \InvalidArgumentException('EntityUpdateManager::trackUpdateOnDeletion called with unkown deletion type: ' . $type);
  }
}