You are here

public function DeployLogger::logEntityCreated in Build Hooks 3.x

Same name and namespace in other branches
  1. 8.2 src/DeployLogger.php \Drupal\build_hooks\DeployLogger::logEntityCreated()

Logs the creation of an entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

1 call to DeployLogger::logEntityCreated()
DeployLogger::logEntityUpdated in src/DeployLogger.php
Logs the updating of an entity.

File

src/DeployLogger.php, line 86

Class

DeployLogger
Defines a class for logging items to be deployed.

Namespace

Drupal\build_hooks

Code

public function logEntityCreated(ContentEntityInterface $entity) {

  /** @var \Drupal\build_hooks\DeploymentStorageHandlerInterface $deployment_storage */
  $deployment_storage = $this->entityTypeManager
    ->getStorage('build_hooks_deployment');
  foreach ($this->entityTypeManager
    ->getStorage('frontend_environment')
    ->loadMultiple() as $environment) {
    $deployment = $deployment_storage
      ->getOrCreateNextDeploymentForEnvironment($environment);
    if (!$this
      ->entityAlreadyExistsInDeployment($deployment, $entity)) {
      $deployment->contents[] = [
        'target_id' => $entity
          ->id(),
        'target_type' => $entity
          ->getEntityTypeId(),
      ];
      $deployment
        ->save();
    }
  }
}