You are here

protected function CreateStubs::createStub in Acquia Content Hub 8.2

Create stub entity.

Parameters

\Acquia\ContentHubClient\CDF\CDFObject $cdf: The CDF object.

string $uuid: The incoming UUID.

\Drupal\Depcalc\DependencyStack $stack: The dependency stack.

\Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher: The dispatcher.

Return value

\Drupal\Core\Entity\EntityInterface The stub entity.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

1 call to CreateStubs::createStub()
CreateStubs::processContentEntities in src/EventSubscriber/ImportFailure/CreateStubs.php
Process content entities.

File

src/EventSubscriber/ImportFailure/CreateStubs.php, line 194

Class

CreateStubs
Class CreateStubs.

Namespace

Drupal\acquia_contenthub\EventSubscriber\ImportFailure

Code

protected function createStub(CDFObject $cdf, string $uuid, DependencyStack $stack, EventDispatcherInterface $dispatcher) : EntityInterface {
  $entity_type = $cdf
    ->getAttribute('entity_type')
    ->getValue()[CDFObject::LANGUAGE_UNDETERMINED];
  $manager = $this
    ->getEntityTypeManager();
  $definition = $manager
    ->getDefinition($entity_type);
  $storage = $manager
    ->getStorage($entity_type);
  $keys = $definition
    ->getKeys();
  $values = $this
    ->getEntityValues($keys, $uuid, $entity_type, $cdf);

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $storage
    ->create($values);
  $this
    ->generateRequiredSampleItems($entity);
  $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();

  // Added to avoid creating new revisions with stubbed data.
  // See \Drupal\content_moderation\Entity\Handler\ModerationHandler.
  if ($entity instanceof SynchronizableInterface) {
    $entity
      ->setSyncing(TRUE);
  }
  $entity
    ->save();
  return $entity;
}