public function Exporter::export in GatherContent 8.5
Exports the changes made in Drupal contents.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity entity object.
\Drupal\gathercontent\Entity\MappingInterface $mapping: Mapping object.
int|null $gcId: GatherContent ID.
array $context: Batch context.
Return value
int|null|string Returns entity ID.
Throws
\Exception
File
- gathercontent_upload/
src/ Export/ Exporter.php, line 173
Class
- Exporter
- Class for handling import/update logic from GatherContent to Drupal.
Namespace
Drupal\gathercontent_upload\ExportCode
public function export(EntityInterface $entity, MappingInterface $mapping, $gcId = NULL, array &$context = []) {
$this->collectedReferenceRevisions = [];
$data = $this
->processGroups($entity, $mapping);
$event = $this->eventDispatcher
->dispatch(GatherUploadContentEvents::PRE_NODE_UPLOAD, new PreNodeUploadEvent($entity, $data));
/** @var \Drupal\gathercontent_upload\Event\PreNodeUploadEvent $event */
$data = $event
->getGathercontentValues();
if (!empty($gcId)) {
$item = $this->client
->itemUpdatePost($gcId, $data['content'], $data['assets']);
$this
->updateFileGcIds($item->assets);
}
else {
$data['name'] = $entity
->label();
$data['template_id'] = $mapping
->getGathercontentTemplateId();
$item = $this->client
->itemPost($mapping
->getGathercontentProjectId(), new Item($data));
$gcId = $item['data']->id;
$this
->updateFileGcIds($item['meta']->assets);
}
$this->eventDispatcher
->dispatch(GatherUploadContentEvents::POST_NODE_UPLOAD, new PostNodeUploadEvent($entity, $data));
if (empty($context['results']['mappings'][$mapping
->id()])) {
$context['results']['mappings'][$mapping
->id()] = [
'mapping' => $mapping,
'gcIds' => [
$gcId => [],
],
];
}
$context['results']['mappings'][$mapping
->id()]['gcIds'][$gcId][] = $entity;
foreach ($this->collectedReferenceRevisions as $reference) {
$context['results']['mappings'][$mapping
->id()]['gcIds'][$gcId][] = $reference;
}
return $entity
->id();
}