public function Importer::import in GatherContent 8.4
Import a single GatherContent item to Drupal.
This function is a replacement for the old _gc_fetcher function.
The caller (e.g. batch processes) should handle the thrown exceptions.
Return value
int The ID of the imported entity.
File
- src/
Import/ Importer.php, line 91
Class
- Importer
- Class for handling import/update logic from GatherContent to Drupal.
Namespace
Drupal\gathercontent\ImportCode
public function import(Item $gc_item, ImportOptions $importOptions) {
$this
->updateStatus($gc_item, $importOptions
->getNewStatus());
$files = $this->client
->itemFilesGet($gc_item->id);
// Let other modules determine the Node to update.
/** @var \Drupal\gathercontent\Event\NodeToUpdateEvent $node_to_update_event */
$node_to_update_event = $this->eventDispatcher
->dispatch(GatherContentEvents::NODE_TO_UPDATE, new NodeToUpdateEvent($gc_item, $files));
$entity = $node_to_update_event
->getNode();
// If no Node to update is set by other modules, determine the Node to
// update or create a new Node.
if (!$entity) {
$entity = $this->contentProcessor
->createNode($gc_item, $importOptions, $files);
}
$this->eventDispatcher
->dispatch(GatherContentEvents::PRE_NODE_SAVE, new PreNodeSaveEvent($entity, $gc_item, $files));
$entity
->save();
$languages = $entity
->getTranslationLanguages();
$translation_id = reset($languages)
->getId();
$entity = $entity
->getTranslation($translation_id);
MenuCreator::createMenu($entity, $importOptions
->getParentMenuItem());
$this->eventDispatcher
->dispatch(GatherContentEvents::POST_NODE_SAVE, new PostNodeSaveEvent($entity, $gc_item, $files));
return $entity
->id();
}