Preview job item entity data.
\Drupal\tmgmt\JobItemInterface $tmgmt_job_item: Job item to be previewed.
string $view_mode: The view mode that should be used to display the entity.
array A render array.
public function preview(JobItemInterface $tmgmt_job_item, $view_mode) {
// Load entity.
$entity = ContentEntitySource::load($tmgmt_job_item
->getItemType(), $tmgmt_job_item
->getItemId(), $tmgmt_job_item
->getJob()
->getSourceLangcode());
// We cannot show the preview for non-existing entities.
if (!$entity) {
throw new NotFoundHttpException();
}
$data = $tmgmt_job_item
->getData();
$target_langcode = $tmgmt_job_item
->getJob()
->getTargetLangcode();
// Populate preview with target translation data.
$preview = $this
->makePreview($entity, $data, $target_langcode);
// Set the entity into preview mode.
$preview->in_preview = TRUE;
// Build view for entity.
$page = $this->entityTypeManager
->getViewBuilder($entity
->getEntityTypeId())
->view($preview, $view_mode, $preview
->language()
->getId());
// The preview is not cacheable.
$page['#cache']['max-age'] = 0;
\Drupal::service('page_cache_kill_switch')
->trigger();
return $page;
}