'tx_vitec_domain_model_product', 'story' => 'tx_vitec_domain_model_usecase', 'market' => 'tx_vitec_domain_model_market', 'solution' => 'tx_vitec_domain_model_solution', ]; #[AsAllowedCallable] public function render(string $content, array $conf): string { $row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null; if ($row && (string)($row['CType'] ?? '') === 'vitec_modelcard') { return $this->renderForRecord($row); } $pageId = 0; $request = $GLOBALS['TYPO3_REQUEST'] ?? null; if ($request !== null) { $pageInfo = $request->getAttribute('frontend.page.information'); if ($pageInfo !== null) { $pageId = (int)$pageInfo->getId(); } } if ($pageId <= 0) { $pageId = (int)($GLOBALS['TSFE']->id ?? 0); } if ($pageId <= 0) { return ''; } $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); $ces = $qb ->select('*') ->from('tt_content') ->where( $qb->expr()->eq('pid', $qb->createNamedParameter($pageId, ParameterType::INTEGER)), $qb->expr()->eq('CType', $qb->createNamedParameter('vitec_modelcard', ParameterType::STRING)), $qb->expr()->eq('deleted', 0), $qb->expr()->eq('hidden', 0) ) ->executeQuery() ->fetchAllAssociative(); if (empty($ces)) { return ''; } return $this->renderForRecord($ces[0]); } /** * @param array $contentElement */ public function renderForRecord(array $contentElement): string { try { $flexFormService = GeneralUtility::makeInstance(FlexFormService::class); $flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? ''); $settings = $flexFormData['settings'] ?? []; $modelType = (string)($settings['modelType'] ?? 'product'); $layout = (string)($settings['layout'] ?? 'vertical'); $debugMode = (bool)($settings['debug'] ?? false); $recordUid = (int)($settings[$modelType === 'story' ? 'story' : $modelType] ?? 0); $item = null; if ($recordUid > 0 && isset(self::MODEL_TABLES[$modelType])) { $row = $this->fetchRecord(self::MODEL_TABLES[$modelType], $recordUid); if ($row !== null) { $item = $this->serializeItem($modelType, $row); } } $response = [ 'modelType' => $modelType, 'layout' => $layout, 'item' => $item, ]; if ($debugMode) { $response['debug'] = ['recordUid' => $recordUid, 'settings' => $settings]; } return (string)json_encode($response); } catch (\Throwable $e) { return ''; } } /** * @return array|null */ private function fetchRecord(string $table, int $uid): ?array { $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $row = $qb ->select('*') ->from($table) ->where( $qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)), $qb->expr()->eq('deleted', 0), $qb->expr()->eq('hidden', 0) ) ->executeQuery() ->fetchAssociative(); return $row ?: null; } /** * @param array $row * @return array */ private function serializeItem(string $modelType, array $row): array { $serializer = GeneralUtility::makeInstance(UsecaseSerializer::class); $uid = (int)$row['uid']; if ($modelType === 'story') { // Success stories already have the canonical card serialisation. return $serializer->serializeListItem($row); } if ($modelType === 'product') { return [ 'uid' => $uid, 'title' => (string)($row['title'] ?? ''), 'slug' => (string)($row['slug'] ?? ''), 'subtitle' => (string)($row['subtitle'] ?? ''), 'teaser' => (string)($row['teaser'] ?? ''), 'image' => $serializer->image($uid, 'image', 'tx_vitec_domain_model_product') ?? $serializer->image($uid, 'productimage', 'tx_vitec_domain_model_product'), ]; } // market | solution — identical field set. return [ 'uid' => $uid, 'title' => (string)($row['title'] ?? ''), 'subtitle' => (string)($row['subtitle'] ?? ''), 'teaser' => (string)($row['teaser'] ?? ''), 'description' => (string)($row['description'] ?? ''), 'image' => $serializer->image($uid, 'image', self::MODEL_TABLES[$modelType]), ]; } }