cObj stays null, the cObj branch of render() never fires and the * call falls through to page discovery, which picks the FIRST element of * this CType on the page rather than the one actually being rendered. */ public function setContentObjectRenderer(ContentObjectRenderer $cObj): void { $this->cObj = $cObj; } private const TABLE = 'tx_vitec_domain_model_usecase'; #[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_usecaselist') { 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_usecaselist', 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 { // Detail context: when the request carries a story argument the // list stays silent — the usecaseshow plugin on the same page // renders the story. Keeps old SEO URLs on one page. $request = $GLOBALS['TYPO3_REQUEST'] ?? null; $routing = $request?->getAttribute('routing'); $detailParam = null; if ($routing instanceof \TYPO3\CMS\Core\Routing\PageArguments) { $detailParam = $routing->getRouteArguments()['tx_vitec_usecaseshow']['usecase'] ?? null; } if ($detailParam === null || $detailParam === '') { $detailParam = ($request?->getQueryParams() ?? [])['tx_vitec_usecaseshow']['usecase'] ?? null; } if ($detailParam !== null && $detailParam !== '') { return ''; } $flexFormService = GeneralUtility::makeInstance(FlexFormService::class); $flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? ''); $settings = $flexFormData['settings'] ?? []; $debugMode = (bool)($settings['debug'] ?? false); $layout = (string)($settings['layout'] ?? 'grid'); $selectedUids = GeneralUtility::intExplode(',', (string)($settings['usecases'] ?? ''), true); $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE); $rows = $qb ->select('*') ->from(self::TABLE) ->where( $qb->expr()->eq('deleted', 0), $qb->expr()->eq('hidden', 0), $qb->expr()->eq('hideonwebsite', 0) ) ->orderBy('featured', 'DESC') ->addOrderBy('title', 'ASC') ->executeQuery() ->fetchAllAssociative(); $serializer = GeneralUtility::makeInstance(UsecaseSerializer::class); // Detail links: the PUBLIC URL is the PARENT path of the // FlexForm-selected "Single PID" page plus the story slug — // /success-stories/, not /success-stories/story/. // The SuccessStoryPathRewrite middleware maps it back to the // detail subpage at request time. $singlePid = (int)($settings['singlePid'] ?? 0); $detailBase = ''; if ($singlePid > 0) { $detailPath = rtrim($this->resolvePageUrl($singlePid), '/'); $parent = str_contains($detailPath, '/') ? substr($detailPath, 0, (int)strrpos($detailPath, '/')) : ''; $detailBase = $parent !== '' ? $parent : $detailPath; } // Editor-picked stories keep the order they were arranged in. The // full (small) table is fetched once and the sequence rebuilt here: // a SQL IN() would hand the rows back in storage order, and a story // that has meanwhile been hidden simply drops out. Same approach as // MarketListJsonRenderer. if ($selectedUids !== []) { $byUid = []; foreach ($rows as $r) { $byUid[(int)$r['uid']] = $r; } $ordered = []; foreach ($selectedUids as $uid) { if (isset($byUid[$uid])) { $ordered[] = $byUid[$uid]; } } $rows = $ordered; } // Testimonial bands on sub-market/solution pages shipped ALL 70 // stories (226 kB per page, the same quotes on ~90 pages - Seobility // 2026-11-10: 34 pages > 500 kB, 1,846 repeated text blocks). Only // stories with a maintained quote are testimonials; the current // market's stories come first, capped at twelve. Editor-picked // lists stay untouched. if ($layout === 'testimonials' && $selectedUids === []) { $rows = $this->testimonialRows($rows); } $usecases = array_map( static function (array $u) use ($serializer, $detailBase): array { $item = $serializer->serializeListItem($u); // The list cards read url/srcset/alternative only; the card // crop variants cost about 1 kB per story (0102-FE, F8). if (is_array($item['cardImage'] ?? null)) { unset($item['cardImage']['crops']); } // A story with its own detail page wins; only the others // fall back to the Single PID plus the slug, so nothing // changes for the stories that have no page assigned. if (($item['detailUrl'] ?? null) === null) { $item['detailUrl'] = ($detailBase !== '' && ($item['slug'] ?? '') !== '') ? $detailBase . '/' . ltrim((string)$item['slug'], '/') : null; } return $item; }, $rows ); // Envelope with the layout, matching vitec_marketlist. This changed // the payload from a bare array to an object - the front end has to // read `usecases.usecases` instead of iterating `usecases` directly. $response = [ 'layout' => $layout, 'showToolbar' => (bool)($settings['showtoolbar'] ?? false), 'usecases' => $usecases, ]; if ($debugMode) { $response['debug'] = [ 'count' => count($usecases), 'selected' => $selectedUids, 'settings' => $settings, ]; } return (string)json_encode($response); } catch (\Throwable $e) { return ''; } } /** * Resolve a page uid to its frontend path (route enhancer aware). * * Callers here build paths by concatenation, so the empty string stays the * "no link" value; LinkResolver's null is coalesced away. */ /** * Stories for a testimonial band: quoted ones only, current market first, * at most twelve. Falls back to the first twelve rows when no story has * a quote yet. * * @param array> $rows * @return array> */ private function testimonialRows(array $rows): array { $quoted = array_values(array_filter( $rows, static fn (array $r): bool => trim((string)($r['quote'] ?? '')) !== '' )); if ($quoted === []) { return array_slice($rows, 0, 12); } try { $marketUids = $this->currentMarketUids(); if ($marketUids !== []) { $qb = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('tx_vitec_usecase_market_mm'); $inMarket = array_map('intval', $qb ->select('uid_local') ->from('tx_vitec_usecase_market_mm') ->where($qb->expr()->in('uid_foreign', $qb->createNamedParameter($marketUids, \Doctrine\DBAL\ArrayParameterType::INTEGER))) ->executeQuery() ->fetchFirstColumn()); $matching = array_values(array_filter($quoted, static fn (array $r): bool => in_array((int)$r['uid'], $inMarket, true))); if (count($matching) >= 3) { $others = array_values(array_filter($quoted, static fn (array $r): bool => !in_array((int)$r['uid'], $inMarket, true))); $quoted = array_merge($matching, $others); } } } catch (\Throwable $e) { // keep the quoted stories in default order } return array_slice($quoted, 0, 12); } /** * Market records whose detail page lies on the current rootline. * * @return list */ private function currentMarketUids(): array { $request = $GLOBALS['TYPO3_REQUEST'] ?? null; $pageInfo = $request?->getAttribute('frontend.page.information'); if ($pageInfo === null) { return []; } $pageUids = array_values(array_filter(array_map( static fn (array $p): int => (int)($p['uid'] ?? 0), $pageInfo->getRootLine() ))); if ($pageUids === []) { return []; } $qb = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('tx_vitec_domain_model_market'); return array_map('intval', $qb ->select('uid') ->from('tx_vitec_domain_model_market') ->where( $qb->expr()->eq('deleted', 0), $qb->expr()->in('detail_page', $qb->createNamedParameter($pageUids, \Doctrine\DBAL\ArrayParameterType::INTEGER)) ) ->executeQuery() ->fetchFirstColumn()); } private function resolvePageUrl(int $pageUid): string { return LinkResolver::pageUrl($pageUid) ?? ''; } }