You are here

public function ProvisionService::createProvisionedEntity 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::createProvisionedEntity()

Parameters

array $context:

EntityInterface|LtiToolProviderProvision $provision:

Return value

EntityInterface

Throws

InvalidPluginDefinitionException

PluginNotFoundException

Exception

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

File

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

Class

ProvisionService

Namespace

Drupal\lti_tool_provider_provision\Services

Code

public function createProvisionedEntity(array $context, EntityInterface $provision) : EntityInterface {
  $entityType = $provision
    ->get('provision_type')->value;
  $entityBundle = $provision
    ->get('provision_bundle')->value;
  $bundleType = $this->entityTypeManager
    ->getDefinition($entityType)
    ->getKey('bundle');
  $entity = $this->entityTypeManager
    ->getStorage($entityType)
    ->create([
    $bundleType => $entityBundle,
  ]);
  $event = new LtiToolProviderProvisionCreateProvisionedEntityEvent($context, $entity);
  LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $event);
  if ($event
    ->isCancelled()) {
    throw new Exception($event
      ->getMessage());
  }
  $entity = $event
    ->getEntity();
  return $entity;
}