You are here

protected function EntityUpdateManager::trackUpdateOnCreation in Entity Usage 8.3

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

Track updates on creation of potential source entities.

Parameters

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

2 calls to EntityUpdateManager::trackUpdateOnCreation()
EntityUpdateManager::destruct in src/EntityUpdateManager.php
Performs destruct operations.
EntityUpdateManager::recalculateUsageInformation in src/EntityUpdateManager.php
Trigger a new usage calculation for a given source entity.

File

src/EntityUpdateManager.php, line 184

Class

EntityUpdateManager
Class EntityUpdateManager.

Namespace

Drupal\entity_usage

Code

protected function trackUpdateOnCreation(EntityInterface $entity) {
  if (!$this
    ->allowSourceEntityTracking($entity)) {
    return;
  }

  // Call all plugins that want to track entity usages. We need to call this
  // for all translations as well since Drupal stores new revisions for all
  // translations by default when saving an entity.
  if ($entity instanceof TranslatableInterface) {
    foreach ($entity
      ->getTranslationLanguages() as $translation_language) {
      if ($entity
        ->hasTranslation($translation_language
        ->getId())) {

        /** @var \Drupal\Core\Entity\EntityInterface $translation */
        $translation = $entity
          ->getTranslation($translation_language
          ->getId());
        foreach ($this
          ->getEnabledPlugins() as $plugin) {
          $plugin
            ->trackOnEntityCreation($translation);
        }
      }
    }
  }
  else {

    // Not translatable, just call the plugins with the entity itself.
    foreach ($this
      ->getEnabledPlugins() as $plugin) {
      $plugin
        ->trackOnEntityCreation($entity);
    }
  }
}