Unify list plugins, add solution list and per-story detail page

- vitec_usecaselist: layout + record selection like marketlist
- new plugin vitec_solutionlist (spec 7.13.3, key "solutions")
- tx_vitec_domain_model_usecase: detail_page -> resolved detailUrl
  (also gives story cards in vitec_modelcard a link for the first time)
- "Show Toolbar" checkbox on product/market/solution/usecase lists
- spec bumped to v1.9

BREAKING: vitec_productlist and vitec_usecaselist now emit an object
instead of a bare array. Consumers must read products.products and
usecases.usecases. Also found: productlist had a configurable layout
that was never serialised; it is emitted now, but keeps its own 0-3
vocabulary instead of grid/list/carousel.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
orascheandClaude Opus 5 committed 2026-08-17 16:29:06 +02:00
1 parent 4ef3ad0026
commit 12eb40614b
23 files changed
+559 -28

No files matched your search

@@ -45,6 +45,19 @@ class SolutionController extends ActionController
*
* @return ResponseInterface
*/
/**
* action list
*
* Intentionally empty: in headless mode the JSON is produced by
* SolutionListJsonRenderer through TypoScript, so this action never runs.
* It exists because configurePlugin() needs a target - same as
* MarketController::listAction().
*/
public function listAction(): ResponseInterface
{
return $this->htmlResponse();
}
public function showAction(): ResponseInterface
{
$selectedSolutionId = (int)$this->settings['solution'];
@@ -8,6 +8,7 @@ use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
use Evomedien\Vitec\UserFunc\MarketListJsonRenderer;
use Evomedien\Vitec\UserFunc\SolutionListJsonRenderer;
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
@@ -119,6 +120,7 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
'vitec_marketlist' => [MarketListJsonRenderer::class, 'markets'],
'vitec_solutionlist' => [SolutionListJsonRenderer::class, 'solutions'],
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
@@ -19,6 +19,14 @@ class Usecase extends AbstractEntity
*/
protected $slug = '';
/**
* Page that presents this story. 0 = none; the list plugin then falls back
* to its own "Single PID" detail page plus the slug.
*
* @var int
*/
protected $detailPage = 0;
/**
* subtitle
*
@@ -110,6 +118,16 @@ class Usecase extends AbstractEntity
return $this->slug;
}
public function getDetailPage(): int
{
return $this->detailPage;
}
public function setDetailPage(int $detailPage): void
{
$this->detailPage = $detailPage;
}
/**
* @param string $slug
*/
@@ -10,6 +10,7 @@ use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
use Evomedien\Vitec\UserFunc\MarketListJsonRenderer;
use Evomedien\Vitec\UserFunc\SolutionListJsonRenderer;
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
@@ -77,6 +78,7 @@ final class ContentElementResolver
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
'vitec_marketlist' => [MarketListJsonRenderer::class, 'markets'],
'vitec_solutionlist' => [SolutionListJsonRenderer::class, 'solutions'],
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Evomedien\Vitec\Service;
use Doctrine\DBAL\ParameterType;
use Evomedien\Vitec\Service\LinkResolver;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -42,6 +43,10 @@ final class UsecaseSerializer
'uid' => $uid,
'title' => (string)($u['title'] ?? ''),
'slug' => (string)($u['slug'] ?? ''),
// The story's own detail page, when one is set. null means "none",
// and the list plugin then falls back to its Single PID plus the
// slug - which is how every story behaved before the field existed.
'detailUrl' => LinkResolver::pageUrl((int)($u['detail_page'] ?? 0)),
'subtitle' => (string)($u['subtitle'] ?? ''),
'teaser' => (string)($u['teaser'] ?? ''),
'cardImage' => $this->image($uid, 'card_image', null, true),
@@ -18,7 +18,7 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
* UserFunc: render all VITEC markets as JSON (headless).
*
* Output under content.markets:
* { "layout": "grid|list|carousel", "markets": [ … ] }
* { "layout": "grid|list|carousel|50-50", "markets": [ … ] }
*
* Selection semantics (FlexForm `settings.markets`):
* - nothing selected -> ALL visible markets, alphabetical by title
@@ -152,6 +152,7 @@ class MarketListJsonRenderer
$response = [
'layout' => $layout,
'showToolbar' => (bool)($settings['showtoolbar'] ?? false),
'markets' => $markets,
];
@@ -152,20 +152,30 @@ class ProductListJsonRenderer
$productsData[] = $this->serializeProduct($product);
}
// Envelope with layout and toolbar flag, matching the other list
// plugins. This turned the payload from a bare array into an object:
// the front end has to read `products.products` instead of
// iterating `products` directly. `layout` was configurable in the
// FlexForm all along but had never been emitted - note that product
// layouts are numbered 0..3 here, not the grid/list/carousel
// vocabulary the other lists use.
$response = [
'layout' => (string)($settings['layout'] ?? '0'),
'showToolbar' => (bool)($settings['showtoolbar'] ?? false),
'products' => $productsData,
];
if ($debugMode) {
return json_encode([
'products' => $productsData,
'debug' => [
'pageId' => (int)($GLOBALS['TSFE']->id ?? 0),
'categoryUids' => $categoryUids,
'productCount' => count($productsData),
'settings' => $settings,
'fallbackFiles' => $this->collectFallbackFilesFromProducts($productsData),
],
]);
$response['debug'] = [
'pageId' => (int)($GLOBALS['TSFE']->id ?? 0),
'categoryUids' => $categoryUids,
'productCount' => count($productsData),
'settings' => $settings,
'fallbackFiles' => $this->collectFallbackFilesFromProducts($productsData),
];
}
return json_encode($productsData);
return json_encode($response);
} catch (\Throwable $e) {
return '';
}
@@ -0,0 +1,196 @@
<?php
declare(strict_types=1);
namespace Evomedien\Vitec\UserFunc;
use Doctrine\DBAL\ParameterType;
use Evomedien\Vitec\Service\LinkResolver;
use Evomedien\Vitec\Service\RteResolver;
use Evomedien\Vitec\Service\UsecaseSerializer;
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* UserFunc: render all VITEC solutions as JSON (headless).
*
* Output under content.solutions:
* { "layout": "grid|list|carousel|50-50", "solutions": [ … ] }
*
* This is the Solution counterpart the architecture spec asks for in clause
* 7.13.2 - deliberately the same shape as the market list, so the front end can
* serve both with one component.
*
* Selection semantics (FlexForm `settings.solutions`):
* - nothing selected -> ALL visible solutions, alphabetical by title
* (tx_vitec_domain_model_solution has no `sorting` column, same as market)
* - solutions selected -> exactly those, in the order the editor arranged
* them in the FlexForm
*
* The page carrying the plugin is never used as a filter.
*
* Each item uses the same shape as the card payload (ModelcardJsonRenderer,
* model type "solution") and carries `detailUrl`, resolved from the record's
* own `detail_page`. Image resolution is delegated to
* UsecaseSerializer::image() rather than re-implemented inline (clause 9.2).
*
* `render()` = top-level plugin / page discovery. `renderForRecord()` = one
* specific tt_content row (reused by ContainerChildrenProcessor for nested
* plugins). Exception-safe.
*/
class SolutionListJsonRenderer
{
private ?ContentObjectRenderer $cObj = null;
/**
* TYPO3 v14 hands the ContentObjectRenderer over through this setter only -
* ContentObjectRenderer::callUserFunction() duck-types it with
* is_callable([$classObj, 'setContentObjectRenderer']). Without the method
* $this->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_solution';
private const CTYPE = 'vitec_solutionlist';
#[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'] ?? '') === self::CTYPE) {
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(self::CTYPE, 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<string,mixed> $contentElement
*/
public function renderForRecord(array $contentElement): string
{
try {
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
$settings = $flexFormData['settings'] ?? [];
$layout = (string)($settings['layout'] ?? 'grid');
$debugMode = (bool)($settings['debug'] ?? false);
$selectedUids = GeneralUtility::intExplode(',', (string)($settings['solutions'] ?? ''), true);
// Always fetch the full (small) table once - that way a selected
// record that has meanwhile been hidden or deleted simply drops out.
$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)
)
->orderBy('title', 'ASC')
->executeQuery()
->fetchAllAssociative();
$serializer = GeneralUtility::makeInstance(UsecaseSerializer::class);
if ($selectedUids === []) {
$solutions = array_map(
fn(array $r): array => $this->serializeSolution($r, $serializer),
$rows
);
} else {
// Keep the editor's FlexForm order. A SQL IN() would return the
// rows in storage order, so the sequence is rebuilt here.
$byUid = [];
foreach ($rows as $r) {
$byUid[(int)$r['uid']] = $r;
}
$solutions = [];
foreach ($selectedUids as $uid) {
if (isset($byUid[$uid])) {
$solutions[] = $this->serializeSolution($byUid[$uid], $serializer);
}
}
}
$response = [
'layout' => $layout,
'showToolbar' => (bool)($settings['showtoolbar'] ?? false),
'solutions' => $solutions,
];
if ($debugMode) {
$response['debug'] = [
'count' => count($solutions),
'selected' => $selectedUids,
'settings' => $settings,
];
}
return (string)json_encode($response);
} catch (\Throwable $e) {
return '';
}
}
/**
* @param array<string,mixed> $r
* @return array<string,mixed>
*/
private function serializeSolution(array $r, UsecaseSerializer $serializer): array
{
$uid = (int)$r['uid'];
return [
'uid' => $uid,
'title' => (string)($r['title'] ?? ''),
'slug' => (string)($r['slug'] ?? ''),
'subtitle' => (string)($r['subtitle'] ?? ''),
'teaser' => (string)($r['teaser'] ?? ''),
'description' => RteResolver::html($r['description'] ?? ''),
'detailUrl' => LinkResolver::pageUrl((int)($r['detail_page'] ?? 0)),
'image' => $serializer->image($uid, 'image', self::TABLE, true),
];
}
}
@@ -20,6 +20,11 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
* specific tt_content row (reused by ContainerChildrenProcessor for nested
* usecase-list plugins). All serialisation is delegated to UsecaseSerializer.
* Exception-safe.
*
* Payload: { "layout": "grid|list|carousel|50-50", "usecases": [ … ] }
*
* The editor may pick individual stories in the FlexForm; the arranged order is
* the display order. No selection means all stories, featured first.
*/
class UsecaseListJsonRenderer
{
@@ -109,6 +114,8 @@ class UsecaseListJsonRenderer
$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
@@ -139,25 +146,59 @@ class UsecaseListJsonRenderer
$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;
}
$usecases = array_map(
static function (array $u) use ($serializer, $detailBase): array {
$item = $serializer->serializeListItem($u);
$item['detailUrl'] = ($detailBase !== '' && ($item['slug'] ?? '') !== '')
? $detailBase . '/' . ltrim((string)$item['slug'], '/')
: null;
// 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) {
return (string)json_encode([
'usecases' => $usecases,
'debug' => ['count' => count($usecases), 'settings' => $settings],
]);
$response['debug'] = [
'count' => count($usecases),
'selected' => $selectedUids,
'settings' => $settings,
];
}
return (string)json_encode($usecases);
return (string)json_encode($response);
} catch (\Throwable $e) {
return '';
}