- 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>
193 lines
7.0 KiB
PHP
193 lines
7.0 KiB
PHP
<?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 markets as JSON (headless).
|
|
*
|
|
* Output under content.markets:
|
|
* { "layout": "grid|list|carousel|50-50", "markets": [ … ] }
|
|
*
|
|
* Selection semantics (FlexForm `settings.markets`):
|
|
* - nothing selected -> ALL visible markets, alphabetical by title
|
|
* (tx_vitec_domain_model_market has no `sorting` column)
|
|
* - markets 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 "market"), so the frontend can render list and single card with
|
|
* one component. Image resolution is delegated to UsecaseSerializer::image()
|
|
* rather than re-implemented inline (architecture spec, clause 9.2).
|
|
*
|
|
* `render()` = top-level plugin / page discovery. `renderForRecord()` = one
|
|
* specific tt_content row (reused by ContainerChildrenProcessor for nested
|
|
* plugins). Exception-safe.
|
|
*/
|
|
class MarketListJsonRenderer
|
|
{
|
|
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_market';
|
|
private const CTYPE = 'vitec_marketlist';
|
|
|
|
#[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['markets'] ?? ''), 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 === []) {
|
|
$markets = array_map(
|
|
fn(array $r): array => $this->serializeMarket($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;
|
|
}
|
|
$markets = [];
|
|
foreach ($selectedUids as $uid) {
|
|
if (isset($byUid[$uid])) {
|
|
$markets[] = $this->serializeMarket($byUid[$uid], $serializer);
|
|
}
|
|
}
|
|
}
|
|
|
|
$response = [
|
|
'layout' => $layout,
|
|
'showToolbar' => (bool)($settings['showtoolbar'] ?? false),
|
|
'markets' => $markets,
|
|
];
|
|
|
|
if ($debugMode) {
|
|
$response['debug'] = [
|
|
'count' => count($markets),
|
|
'selected' => $selectedUids,
|
|
'settings' => $settings,
|
|
];
|
|
}
|
|
|
|
return (string)json_encode($response);
|
|
} catch (\Throwable $e) {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string,mixed> $r
|
|
* @return array<string,mixed>
|
|
*/
|
|
private function serializeMarket(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),
|
|
];
|
|
}
|
|
}
|