protected function ProcessHighPriorityEntities::createHighPriorityEntity in Acquia Content Hub 8.2
Creates entity and dispatches necessary events.
Parameters
\Acquia\ContentHubClient\CDF\CDFObject $cdf: The imported CDF object.
\Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher: The event dispatcher.
\Drupal\depcalc\DependencyStack $stack: The dependency stack from this event.
Return value
\Drupal\Core\Entity\EntityInterface The created entity.
Throws
\Drupal\Core\Entity\EntityStorageException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
1 call to ProcessHighPriorityEntities::createHighPriorityEntity()
- ProcessHighPriorityEntities::processHighPriorityEntity in src/
EventSubscriber/ ImportFailure/ ProcessHighPriorityEntities.php - Creates entity if it doesn't exist or returns the existing one.
File
- src/
EventSubscriber/ ImportFailure/ ProcessHighPriorityEntities.php, line 117
Class
- ProcessHighPriorityEntities
- Class ProcessHighPriorityEntities.
Namespace
Drupal\acquia_contenthub\EventSubscriber\ImportFailureCode
protected function createHighPriorityEntity(CDFObject $cdf, EventDispatcherInterface $dispatcher, DependencyStack $stack) : EntityInterface {
$manager = $this
->getEntityTypeManager();
$entity_type = $cdf
->getAttribute('entity_type')
->getValue()['und'];
$storage = $manager
->getStorage($entity_type);
$default_langcode = $cdf
->getMetadata()['default_language'];
$data = Yaml::decode(base64_decode($cdf
->getMetadata()['data']));
$default_values = $data[$default_langcode];
$entity = $storage
->create($default_values);
$pre_entity_save_event = new PreEntitySaveEvent($entity, $stack, $cdf);
$dispatcher
->dispatch(AcquiaContentHubEvents::PRE_ENTITY_SAVE, $pre_entity_save_event);
$entity = $pre_entity_save_event
->getEntity();
$entity
->save();
return $entity;
}