You are here

public function EntityUpdateManager::trackUpdateOnDeletion in Entity Usage 8.2

Same name and namespace in other branches
  1. 8 src/EntityUpdateManager.php \Drupal\entity_usage\EntityUpdateManager::trackUpdateOnDeletion()
  2. 8.3 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

File

src/EntityUpdateManager.php, line 135

Class

EntityUpdateManager
Class EntityUpdateManager.

Namespace

Drupal\entity_usage

Code

public 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);
  }
}