You are here

public function DependentEntityWrapper::__construct in Dependency Calculation 8

DependentEntityWrapper constructor.

The entity object is thrown away within this constructor and just the bare minimum of details to reconstruct it are kept. This is to reduce memory overhead during the run time of dependency calculation.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which we are calculating dependencies.

bool $additional_processing: Whether or not the entity will require additional processing.

Throws

\Exception

File

src/DependentEntityWrapper.php, line 91

Class

DependentEntityWrapper
An entity wrapper class for finding and tracking dependencies of an entity.

Namespace

Drupal\depcalc

Code

public function __construct(EntityInterface $entity, $additional_processing = FALSE) {
  $this->entityTypeId = $entity
    ->getEntityTypeId();
  $this->id = $entity
    ->id();
  $uuid = $entity
    ->uuid();
  $this->hash = sha1(json_encode($entity
    ->toArray()));
  if (empty($uuid)) {
    throw new \Exception(sprintf("The entity of type %s by id %s does not have a UUID. This indicates a larger problem with your application and should be remedied before attempting to calculate dependencies.", $this->entityTypeId, $this->id));
  }
  $this->uuid = $uuid;
  $this->additionalProcessing = $additional_processing;
}