You are here

public function ProvisionService::syncProvisionedEntity in LTI Tool Provider 8

Same name and namespace in other branches
  1. 2.x modules/lti_tool_provider_provision/src/Services/ProvisionService.php \Drupal\lti_tool_provider_provision\Services\ProvisionService::syncProvisionedEntity()

Parameters

array $context:

EntityInterface $entity:

Return value

EntityInterface

Throws

Exception

1 call to ProvisionService::syncProvisionedEntity()
ProvisionService::provision in modules/lti_tool_provider_provision/src/Services/ProvisionService.php

File

modules/lti_tool_provider_provision/src/Services/ProvisionService.php, line 151

Class

ProvisionService

Namespace

Drupal\lti_tool_provider_provision\Services

Code

public function syncProvisionedEntity(array $context, EntityInterface $entity) : EntityInterface {
  $entityDefaults = $this->config
    ->get('entity_defaults');
  if ($entityDefaults) {
    foreach ($entityDefaults as $name => $entityDefault) {
      if ($entity instanceof ContentEntityBase && isset($context[$entityDefault]) && !empty($context[$entityDefault])) {
        $entity
          ->set($name, $context[$entityDefault]);
      }
    }
  }
  $event = new LtiToolProviderProvisionSyncProvisionedEntityEvent($context, $entity);
  LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $event);
  if ($event
    ->isCancelled()) {
    throw new Exception($event
      ->getMessage());
  }
  $entity = $event
    ->getEntity();
  return $entity;
}