cType)) { throw new ConfigurationMissingException('Property cType must not be empty', 1586703436); } } public function preProcess( PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row ) { $this->data = &$row; if ($this->isCtypeMatching() && $this->checkTemplateFile()) { $drawItem = false; $headerContent = $this->getHeaderContent(); $itemContent .= $this->getBodytext(); } } protected function getHeaderContent(): string { return '
'; } protected function getBodytext(): string { /** @var ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $standaloneView = $objectManager->get(StandaloneView::class); $standaloneView->setTemplatePathAndFilename($this->getTemplateFile()); $standaloneView->assignMultiple($this->getAssignmentsForTemplate() + [ 'data' => $this->data, 'flexForm' => $this->getFlexForm(), 'firstImage' => count($this->getImages()) > 0 ? $this->getImages()[0] : null, 'images' => $this->getImages() ]); return $standaloneView->render(); } protected function getAssignmentsForTemplate(): array { return []; } protected function getFlexForm(): array { /** @var ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $flexFormService = $objectManager->get(FlexFormService::class); return $flexFormService->convertFlexFormContentToArray($this->data['pi_flexform']); } protected function getImages(int $uid = null, string $tablenames = 'tt_content', string $fieldname = 'image'): array { $uid = $uid ?? $this->data['uid']; $references = []; /** @var ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $fileRepository = $objectManager->get(FileRepository::class); /** @var ConnectionPool $connectionPool */ $connectionPool = $objectManager->get(ConnectionPool::class); $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file_reference'); $identifiers = (array)$queryBuilder ->select('uid') ->from('sys_file_reference') ->where('uid_foreign=' . $uid . ' and tablenames="' . $tablenames . '" and fieldname="' . $fieldname . '"') ->execute() ->fetch(\PDO::FETCH_COLUMN); foreach ($identifiers as $identifier) { if ($identifier > 0) { $reference = $fileRepository->findFileReferenceByUid($identifier); if ($reference !== null) { $references[] = $reference; } } } return $references; } /** * @return bool */ protected function isCtypeMatching(): bool { return $this->data['CType'] === $this->cType; } protected function checkTemplateFile(): bool { if (is_file($this->getTemplateFile()) === false) { throw new TemplateFileMissingException( 'Expected template file for preview rendering for CType ' . $this->cType . ' is missing', 1586703260 ); } return true; } protected function getTemplateFile(): string { return GeneralUtility::getFileAbsFileName( $this->templatePath . GeneralUtility::underscoredToUpperCamelCase($this->data['CType']) . '.html' ); } }