You are here

public function EntityUpdateManager::trackUpdateOnDeletion in Entity Usage 8

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

Track updates on deletion of potential host entities.

Parameters

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

File

src/EntityUpdateManager.php, line 72

Class

EntityUpdateManager
Class EntityUpdateManager.

Namespace

Drupal\entity_usage

Code

public function trackUpdateOnDeletion(ContentEntityInterface $entity) {

  // Only act on content entities.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }

  // Call all plugins that want to track entity usages.
  foreach ($this->trackManager
    ->getDefinitions() as $plugin_id => $plugin_definition) {

    /** @var EntityUsageTrackInterface $instance */
    $instance = $this->trackManager
      ->createInstance($plugin_id);
    $instance
      ->trackOnEntityDeletion($entity);
  }

  // Now clean the possible usage of the entity that was deleted when target.
  $this->usageService
    ->delete($entity
    ->id(), $entity
    ->getEntityTypeId());
}