Checkpoint: headless JSON architecture documented + cleanup (Stufe 1+2)

Restore point before Stufe 3 (central resolver-service refactoring).

Includes this session's work:
- Success Story (usecase) rebuild: new fields/tabs, UsecaseSerializer,
  thin List/Show renderers, MM relations, inline content elements.
- vitec_columns content block (two-column layout with per-item content)
  incl. unified header section; special-cased JSON resolution.
- Container per-column flex (items[].config align/justify) + gap on parent.
- Unified header section across CEs/plugins/containers; header fields in JSON.
- ISO-style architecture spec: Documentation/Headless-JSON-Architecture.md.
- Cleanup: removed local scratch + verified .bak backups.
- Fixes: B-6 (undefined thumbnail variable in Downloadcardcollection image
  resolver), B-7 (unsatisfiable legacy CType OR branch in Downloadcard/Datasheets).

Rollback: git reset --hard snapshot-2026-07-09-pre-stufe3

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
o-rascheandClaude Opus 4.8 committed 2026-07-09 10:01:56 +02:00
1 parent c6759186cb
commit bb7c03235d
237 files changed
+6698 -1749

No files matched your search

+173 -15
View File
@@ -7,6 +7,7 @@ namespace Evomedien\Vitec\UserFunc;
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
use Doctrine\DBAL\ParameterType;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -44,20 +45,12 @@ class DownloadcardJsonRenderer
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tt_content');
// After v14 migration the CType is the plugin signature; for legacy
// (unmigrated) records the CType is still "list" with list_type set.
$rows = $qb
->select('*')
->from('tt_content')
->where(
$qb->expr()->eq('pid', $qb->createNamedParameter($pageId, ParameterType::INTEGER)),
$qb->expr()->or(
$qb->expr()->eq('CType', $qb->createNamedParameter('vitec_downloadcard', ParameterType::STRING)),
$qb->expr()->and(
$qb->expr()->eq('CType', $qb->createNamedParameter('list', ParameterType::STRING)),
$qb->expr()->eq('CType', $qb->createNamedParameter('vitec_downloadcard', ParameterType::STRING))
)
),
$qb->expr()->eq('CType', $qb->createNamedParameter('vitec_downloadcard', ParameterType::STRING)),
$qb->expr()->eq('deleted', 0),
$qb->expr()->eq('hidden', 0)
)
@@ -106,14 +99,17 @@ class DownloadcardJsonRenderer
: '';
}
$serializedDownload = $this->serializeDownload($download);
$response = [
'mode' => 'single',
'download' => $this->serializeDownload($download),
'download' => $serializedDownload,
'settings' => $settingsOut,
];
if ($debugMode) {
$response['debug'] = [
'pageId' => $pageId, 'downloadUid' => $downloadUid, 'settings' => $settings,
'fallbackFiles' => $this->collectFallbackFilesFromDownloads([$serializedDownload]),
];
}
return json_encode($response);
@@ -123,11 +119,12 @@ class DownloadcardJsonRenderer
if ($productUid > 0) {
$downloads = $this->fetchDownloadsForProduct($productUid);
$product = $this->fetchProductContext($productUid);
$serializedDownloads = array_map(fn($r) => $this->serializeDownload($r), $downloads);
$response = [
'mode' => 'product-downloads',
'product' => $product,
'downloads' => array_map(fn($r) => $this->serializeDownload($r), $downloads),
'downloads' => $serializedDownloads,
'settings' => $settingsOut,
];
if ($debugMode) {
@@ -136,6 +133,7 @@ class DownloadcardJsonRenderer
'productUid' => $productUid,
'downloadCount' => count($downloads),
'settings' => $settings,
'fallbackFiles' => $this->collectFallbackFilesFromDownloads($serializedDownloads),
];
}
return json_encode($response);
@@ -248,6 +246,8 @@ class DownloadcardJsonRenderer
protected function serializeDownload(array $download): array
{
$uid = (int)$download['uid'];
$fileprefix = (string)($download['fileprefix'] ?? '');
$filetype = $this->getDownloadFileType($uid);
return [
'uid' => $uid,
@@ -258,22 +258,60 @@ class DownloadcardJsonRenderer
'keywords' => (string)($download['keywords'] ?? ''),
'icon' => (string)($download['icon'] ?? ''),
'filepath' => (string)($download['filepath'] ?? ''),
'fileprefix' => (string)($download['fileprefix'] ?? ''),
'fileprefix' => $fileprefix,
'filetype' => $filetype,
'private_download' => (bool)($download['private_download'] ?? false),
'hideonapp' => (bool)($download['hideonapp'] ?? false),
'hideonwebsite' => (bool)($download['hideonwebsite'] ?? false),
'hideondatasheets' => (bool)($download['hideondatasheets'] ?? false),
'hideonproducts' => (bool)($download['hideonproducts'] ?? false),
'file' => $this->getDownloadFile($uid),
'file' => $this->getDownloadFile($uid, $fileprefix, $filetype),
];
}
private function getDownloadFileType(int $downloadUid): string
{
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_category');
$categories = $qb
->select('c.filetype')
->from('sys_category', 'c')
->join(
'c',
'sys_category_record_mm',
'mm',
'mm.uid_local = c.uid AND mm.tablenames = ' .
$qb->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING) .
' AND mm.fieldname = ' .
$qb->createNamedParameter('categories', ParameterType::STRING)
)
->where(
$qb->expr()->eq('mm.uid_foreign', $qb->createNamedParameter($downloadUid, ParameterType::INTEGER)),
$qb->expr()->eq('c.deleted', 0),
$qb->expr()->eq('c.hidden', 0),
$qb->expr()->eq('c.parent', $qb->createNamedParameter(4, ParameterType::INTEGER))
)
->orderBy('mm.sorting', 'ASC')
->executeQuery()
->fetchAllAssociative();
foreach ($categories as $category) {
$filetype = trim((string)($category['filetype'] ?? ''));
if ($filetype !== '') {
return $filetype;
}
}
return '';
}
/**
* Resolve the FAL file reference (fieldname=file) for a download.
*
* @return array<string,mixed>|null
*/
protected function getDownloadFile(int $downloadUid): ?array
protected function getDownloadFile(int $downloadUid, string $fileprefix = '', string $filetype = ''): ?array
{
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_file_reference');
@@ -295,7 +333,7 @@ class DownloadcardJsonRenderer
->fetchAssociative();
if (!$row) {
return null;
return $this->resolveFileByConvention($fileprefix, $filetype);
}
$thumbnailUrl = null;
@@ -324,4 +362,124 @@ class DownloadcardJsonRenderer
'description' => (string)($row['description'] ?? ''),
];
}
/**
* @return array<string,mixed>|null
*/
private function resolveFileByConvention(string $fileprefix, string $filetype): ?array
{
$fileprefix = trim($fileprefix);
$filetype = trim($filetype);
if ($fileprefix === '' || $filetype === '') {
return null;
}
$baseDir = Environment::getPublicPath() . '/fileadmin/downloads/Collateral';
if (!is_dir($baseDir) || !is_readable($baseDir)) {
return null;
}
$escapedPrefix = preg_quote($fileprefix, '/');
$escapedType = preg_quote($filetype, '/');
$pattern = '/^' . $escapedPrefix . '__' . $escapedType . '__(\\d+)-([A-Za-z]+)\\.([A-Za-z0-9]+)$/';
$bestFile = null;
$bestNumber = -1;
$bestLetterRank = -1;
$entries = scandir($baseDir);
if ($entries === false) {
return null;
}
foreach ($entries as $entry) {
if (!is_string($entry) || $entry === '.' || $entry === '..') {
continue;
}
if (!preg_match($pattern, $entry, $matches)) {
continue;
}
$number = (int)$matches[1];
$letterRank = $this->letterSequenceToRank((string)$matches[2]);
if ($number > $bestNumber || ($number === $bestNumber && $letterRank > $bestLetterRank)) {
$bestNumber = $number;
$bestLetterRank = $letterRank;
$bestFile = $entry;
}
}
if ($bestFile === null) {
return null;
}
$fullPath = $baseDir . '/' . $bestFile;
if (!is_file($fullPath) || !is_readable($fullPath)) {
return null;
}
$extension = strtolower(pathinfo($bestFile, PATHINFO_EXTENSION));
$mimeType = function_exists('mime_content_type') ? (string)(mime_content_type($fullPath) ?: '') : '';
return [
'uid' => 0,
'name' => $bestFile,
'url' => '/fileadmin/downloads/Collateral/' . rawurlencode($bestFile),
'thumbnail' => null,
'size' => (int)(filesize($fullPath) ?: 0),
'extension' => $extension,
'mimeType' => $mimeType,
'title' => '',
'description' => '',
];
}
private function letterSequenceToRank(string $letters): int
{
$rank = 0;
$letters = strtoupper($letters);
$length = strlen($letters);
for ($i = 0; $i < $length; $i++) {
$char = ord($letters[$i]);
if ($char < 65 || $char > 90) {
continue;
}
$rank = ($rank * 26) + ($char - 64);
}
return $rank;
}
/**
* @param array<int,array<string,mixed>> $downloads
* @return array<int,array<string,mixed>>
*/
private function collectFallbackFilesFromDownloads(array $downloads): array
{
$fallbackFiles = [];
foreach ($downloads as $download) {
$file = $download['file'] ?? null;
if (!is_array($file)) {
continue;
}
if ((int)($file['uid'] ?? 1) !== 0) {
continue;
}
$fallbackFiles[] = [
'downloadUid' => (int)($download['uid'] ?? 0),
'name' => (string)($file['name'] ?? ''),
'url' => (string)($file['url'] ?? ''),
'source' => 'naming-convention-fallback',
];
}
return $fallbackFiles;
}
}