VITEC headless v14: 5-bug fix unifies plugin renderers + cleanup
Resolves a cascade of TYPO3 v14 breaking changes that left every VITEC plugin's JSON output silently empty: 1. `list_type` column dropped — all renderer page-discovery queries now filter by `CType = 'vitec_X'`. 2. `#[AsAllowedCallable]` attribute added to every public render() — without it v14 throws AllowedCallableException, which headless silently filters via its "Oops, an error occurred!" guard. 3. `$GLOBALS['TSFE']->id` is null inside JSON cObj context — page id now read from the `frontend.page.information` request attribute (TSFE fallback kept for legacy entry points). 4. page.tsconfig wizard items migrated to `CType = vitec_X` directly (legacy `CType=list, list_type=...` no longer exists in v14). 5. ContainerChildrenProcessor + ContentElementResolver dispatch the PLUGIN_RENDERERS map by CType (primary) with list_type fallback. Beyond the bug fix this commit also contains: - Datasheets renderer rewritten to "products with newest datasheet" semantics (filtered via Download.hideondatasheets). - New vitec/card content block — multi-purpose card with backend preview and layout/background/aspect/alignment/border/shadow options. - New vitec_container CType (b13 single-column container, FlexForm cssClass propagated into the JSON envelope). - ContentElementResolver service for contentelement/contentelementcta link resolution; ContainerChildrenProcessor for nested plugin resolution inside b13 containers. - Vitecset setup.typoscript: ContentElement import moved to top so lib.contentElement is defined before VITEC's tt_content blocks. - Cleanup: 98 .bak.<timestamp> debugging backups removed; *.bak.* and /public/_assets_install/ added to .gitignore. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
64ea55d29d
commit
3aaf8fdad5
98 files changed
+5650
-10154
No files matched your search
Executable → Regular
+77
-3
@@ -3,6 +3,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\DataProcessing;
|
||||
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -15,6 +22,11 @@ use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
* `data` only contains non-empty content-relevant fields.
|
||||
*
|
||||
* VITEC list-plugins nested as container children (productlist, productshow,
|
||||
* usecaselist, usecaseshow) are resolved to the SAME JSON the top-level
|
||||
* headless rendering produces, injected into `data` under their respective
|
||||
* key. The raw pi_flexform XML is then dropped from `data`.
|
||||
*
|
||||
* Exception-safe.
|
||||
*/
|
||||
final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
@@ -27,7 +39,6 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
// versioning / language / workspace / housekeeping
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
@@ -38,8 +49,6 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter', // legacy
|
||||
// TCA defaults that TYPO3 always sets on every tt_content row,
|
||||
// regardless of CType — rarely relevant to the frontend:
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
@@ -53,6 +62,22 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
'header_layout',
|
||||
];
|
||||
|
||||
/**
|
||||
* Nested VITEC list-plugins: list_type => [ rendererClass, jsonKey ].
|
||||
* The renderer's renderForRecord() is invoked with the child's own
|
||||
* tt_content row so the result is record-accurate (works with multiple
|
||||
* containers / plugins on the same page).
|
||||
*/
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
];
|
||||
|
||||
public function process(
|
||||
ContentObjectRenderer $cObj,
|
||||
array $contentObjectConfiguration,
|
||||
@@ -124,6 +149,9 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
$data[$field] = $this->castValue($field, $value);
|
||||
}
|
||||
|
||||
// Resolve nested VITEC list-plugins to their headless JSON.
|
||||
$this->resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
@@ -139,6 +167,52 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the child is a VITEC list-plugin, run its JSON renderer for THIS
|
||||
* record and inject the decoded result under its key. Drops the raw
|
||||
* pi_flexform XML afterwards. Never throws.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
|
||||
// The raw FlexForm XML is noise once the plugin is resolved.
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// Leave the raw data untouched on any failure.
|
||||
}
|
||||
}
|
||||
|
||||
private function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\DataProcessing;
|
||||
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardcollectionJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* Collect container children grouped by colPos and emit a lean, transport-
|
||||
* ready structure. Each child is normalised to:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
* `data` only contains non-empty content-relevant fields.
|
||||
*
|
||||
* VITEC list-plugins nested as container children (productlist, productshow,
|
||||
* usecaselist, usecaseshow) are resolved to the SAME JSON the top-level
|
||||
* headless rendering produces, injected into `data` under their respective
|
||||
* key. The raw pi_flexform XML is then dropped from `data`.
|
||||
*
|
||||
* Exception-safe.
|
||||
*/
|
||||
final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter', // legacy
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
/** Fields whose 0/empty value is still meaningful. */
|
||||
private const KEEP_IF_ZERO = [
|
||||
'header_layout',
|
||||
];
|
||||
|
||||
/**
|
||||
* Nested VITEC list-plugins: list_type => [ rendererClass, jsonKey ].
|
||||
* The renderer's renderForRecord() is invoked with the child's own
|
||||
* tt_content row so the result is record-accurate (works with multiple
|
||||
* containers / plugins on the same page).
|
||||
*/
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
|
||||
];
|
||||
|
||||
public function process(
|
||||
ContentObjectRenderer $cObj,
|
||||
array $contentObjectConfiguration,
|
||||
array $processorConfiguration,
|
||||
array $processedData
|
||||
): array {
|
||||
$as = (string)($processorConfiguration['as'] ?? 'items');
|
||||
|
||||
try {
|
||||
$parentUid = (int)($cObj->data['uid'] ?? 0);
|
||||
if ($parentUid <= 0) {
|
||||
$processedData[$as] = [];
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
$pid = (int)($cObj->data['pid'] ?? 0);
|
||||
$sysLanguageUid = (int)($cObj->data['sys_language_uid'] ?? 0);
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$rows = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('tx_container_parent', $qb->createNamedParameter($parentUid, Connection::PARAM_INT)),
|
||||
$qb->expr()->eq('pid', $qb->createNamedParameter($pid, Connection::PARAM_INT)),
|
||||
$qb->expr()->eq('sys_language_uid', $qb->createNamedParameter($sysLanguageUid, Connection::PARAM_INT))
|
||||
)
|
||||
->orderBy('colPos')
|
||||
->addOrderBy('sorting')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$byColPos = [];
|
||||
foreach ($rows as $record) {
|
||||
$byColPos[(int)$record['colPos']][] = $this->normalise($record);
|
||||
}
|
||||
ksort($byColPos);
|
||||
|
||||
$items = [];
|
||||
foreach ($byColPos as $colPos => $contentElements) {
|
||||
$items[] = [
|
||||
'config' => ['colPos' => $colPos],
|
||||
'contentElements' => $contentElements,
|
||||
];
|
||||
}
|
||||
|
||||
$processedData[$as] = $items;
|
||||
} catch (\Throwable $e) {
|
||||
$processedData[$as] = [];
|
||||
}
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
private function normalise(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($this->isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = $this->castValue($field, $value);
|
||||
}
|
||||
|
||||
// Resolve nested VITEC list-plugins to their headless JSON.
|
||||
$this->resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)$record['colPos'],
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the child is a VITEC list-plugin, run its JSON renderer for THIS
|
||||
* record and inject the decoded result under its key. Drops the raw
|
||||
* pi_flexform XML afterwards. Never throws.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
|
||||
// The raw FlexForm XML is noise once the plugin is resolved.
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// Leave the raw data untouched on any failure.
|
||||
}
|
||||
}
|
||||
|
||||
private function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null
|
||||
|| $value === ''
|
||||
|| $value === 0
|
||||
|| $value === '0';
|
||||
}
|
||||
|
||||
private function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+16
-2
@@ -7,6 +7,11 @@ use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardcollectionJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DatasheetsJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -70,6 +75,11 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
|
||||
'vitec_datasheets' => [DatasheetsJsonRenderer::class, 'datasheets'],
|
||||
];
|
||||
|
||||
public function process(
|
||||
@@ -171,13 +181,17 @@ final class ContainerChildrenProcessor implements DataProcessorInterface
|
||||
*/
|
||||
private function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
if ($listType === '' || !isset(self::PLUGIN_RENDERERS[$listType])) {
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$listType];
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
|
||||
Executable → Regular
File mode changed.
@@ -1,922 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This file is part of the "VITEC" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* (c) 2025
|
||||
*/
|
||||
|
||||
/**
|
||||
* Product
|
||||
*/
|
||||
class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* title
|
||||
*
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* slug
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $slug;
|
||||
|
||||
/**
|
||||
* urltitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $urltitle = '';
|
||||
|
||||
/**
|
||||
* seotitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $seotitle = '';
|
||||
|
||||
/**
|
||||
* seometa
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $seometa = '';
|
||||
|
||||
/**
|
||||
* keywords
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keywords = '';
|
||||
|
||||
/**
|
||||
* structureddata
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $structureddata = '';
|
||||
|
||||
/**
|
||||
* teaser
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $teaser = '';
|
||||
|
||||
/**
|
||||
* subtitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subtitle = '';
|
||||
|
||||
/**
|
||||
* video
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $video = '';
|
||||
|
||||
/**
|
||||
* hideonapp
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonapp = false;
|
||||
|
||||
/**
|
||||
* hideonwebsite
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonwebsite = false;
|
||||
|
||||
/**
|
||||
* hideondatasheets
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideondatasheets = false;
|
||||
|
||||
/**
|
||||
* hideonproducts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonproducts = false;
|
||||
|
||||
/**
|
||||
* applications
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $applications = '';
|
||||
|
||||
/**
|
||||
* description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
|
||||
/**
|
||||
* highlights
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $highlights = '';
|
||||
|
||||
/**
|
||||
* shortcut
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shortcut = false;
|
||||
|
||||
/**
|
||||
* shortcutpid
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shortcutpid = '';
|
||||
|
||||
/**
|
||||
* legacy
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $legacy = false;
|
||||
|
||||
/**
|
||||
* supportproduct
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $supportproduct = false;
|
||||
|
||||
/**
|
||||
* subproduct
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $subproduct = false;
|
||||
|
||||
/**
|
||||
* @var ObjectStorage<Category>
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Product images
|
||||
*
|
||||
* @var ObjectStorage<FileReference>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $productimage;
|
||||
|
||||
/**
|
||||
* Downloads
|
||||
*
|
||||
* @var ObjectStorage<\Evomedien\Vitec\Domain\Model\Download>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $downloads;
|
||||
|
||||
|
||||
/**
|
||||
* Open Graph Image
|
||||
*
|
||||
* @var FileReference
|
||||
*/
|
||||
protected $ogimage;
|
||||
|
||||
/**
|
||||
* Content element link - Key Features
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contentelement;
|
||||
|
||||
/**
|
||||
* Content element link - CTA Features
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contentelementcta;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Evomedien\Vitec\Domain\Model\Product>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $relatedprodukt;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Returns the title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title
|
||||
*
|
||||
* @param string $title
|
||||
* @return void
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the video
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVideo()
|
||||
{
|
||||
return $this->video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the video
|
||||
*
|
||||
* @param string $video
|
||||
* @return void
|
||||
*/
|
||||
public function setVideo(string $video)
|
||||
{
|
||||
$this->video = $video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the slug
|
||||
*
|
||||
* @param string $slug
|
||||
* @return void
|
||||
*/
|
||||
public function setSlug(string $slug)
|
||||
{
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the urltitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrltitle()
|
||||
{
|
||||
return $this->urltitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the urltitle
|
||||
*
|
||||
* @param string $urltitle
|
||||
* @return void
|
||||
*/
|
||||
public function setUrltitle(string $urltitle)
|
||||
{
|
||||
$this->urltitle = $urltitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the seotitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSeotitle()
|
||||
{
|
||||
return $this->seotitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seotitle
|
||||
*
|
||||
* @param string $seotitle
|
||||
* @return void
|
||||
*/
|
||||
public function setSeotitle(string $seotitle)
|
||||
{
|
||||
$this->seotitle = $seotitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the seometa
|
||||
*
|
||||
* @return string $seometa
|
||||
*/
|
||||
public function getSeometa()
|
||||
{
|
||||
return $this->seometa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seometa
|
||||
*
|
||||
* @param string $seometa
|
||||
* @return void
|
||||
*/
|
||||
public function setSeometa($seometa)
|
||||
{
|
||||
$this->seometa = $seometa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keywords
|
||||
*
|
||||
* @return string $keywords
|
||||
*/
|
||||
public function getKeywords()
|
||||
{
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the keywords
|
||||
*
|
||||
* @param string $keywords
|
||||
* @return void
|
||||
*/
|
||||
public function setKeywords($keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teaser
|
||||
*
|
||||
* @return string $kteasereywords
|
||||
*/
|
||||
public function getTeaser()
|
||||
{
|
||||
return $this->teaser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the teaser
|
||||
*
|
||||
* @param string $teaser
|
||||
* @return void
|
||||
*/
|
||||
public function setTeaser($teaser)
|
||||
{
|
||||
$this->teaser = $teaser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subtitle
|
||||
*
|
||||
* @return string $subtitle
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
return $this->subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subtitle
|
||||
*
|
||||
* @param string $subtitle
|
||||
* @return void
|
||||
*/
|
||||
public function setSubtitle($subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonapp
|
||||
*
|
||||
* @return bool $hideonapp
|
||||
*/
|
||||
public function getHideonapp()
|
||||
{
|
||||
return $this->hideonapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonapp
|
||||
*
|
||||
* @param bool $hideonapp
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonapp($hideonapp)
|
||||
{
|
||||
$this->hideonapp = $hideonapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description
|
||||
*
|
||||
* @return bool $description
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description
|
||||
*
|
||||
* @param bool $description
|
||||
* @return void
|
||||
*/
|
||||
public function setDescriptionp($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonwebsite
|
||||
*
|
||||
* @return bool $hideonwebsite
|
||||
*/
|
||||
public function getHideonwebsite()
|
||||
{
|
||||
return $this->hideonwebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonwebsite
|
||||
*
|
||||
* @param bool $hideonwebsite
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonwebsite($hideonwebsite)
|
||||
{
|
||||
$this->hideonwebsite = $hideonwebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideondatasheets
|
||||
*
|
||||
* @return bool $hideondatasheets
|
||||
*/
|
||||
public function getHideondatasheets()
|
||||
{
|
||||
return $this->hideondatasheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideondatasheets
|
||||
*
|
||||
* @param bool $hideondatasheets
|
||||
* @return void
|
||||
*/
|
||||
public function setHideondatasheets($hideondatasheets)
|
||||
{
|
||||
$this->hideondatasheets = $hideondatasheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonproducts
|
||||
*
|
||||
* @return bool $hideonproducts
|
||||
*/
|
||||
public function getHideonproducts()
|
||||
{
|
||||
return $this->hideonproducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonproducts
|
||||
*
|
||||
* @param bool $hideonproducts
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonproducts($hideonproducts)
|
||||
{
|
||||
$this->hideonproducts = $hideonproducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the structureddata
|
||||
*
|
||||
* @return string $structureddata
|
||||
*/
|
||||
public function getStructureddata()
|
||||
{
|
||||
return $this->structureddata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the structureddata
|
||||
*
|
||||
* @param string $structureddata
|
||||
* @return void
|
||||
*/
|
||||
public function setStructureddata($structureddata)
|
||||
{
|
||||
$this->structureddata = $structureddata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the applications
|
||||
*
|
||||
* @return string $applications
|
||||
*/
|
||||
public function getApplications()
|
||||
{
|
||||
return $this->applications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the applications
|
||||
*
|
||||
* @param string $applications
|
||||
* @return void
|
||||
*/
|
||||
public function setApplications($applications)
|
||||
{
|
||||
$this->applications = $applications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highlights
|
||||
*
|
||||
* @return string $highlights
|
||||
*/
|
||||
public function getHighlights()
|
||||
{
|
||||
return $this->highlights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the highlights
|
||||
*
|
||||
* @param string $highlights
|
||||
* @return void
|
||||
*/
|
||||
public function setHighlights($highlights)
|
||||
{
|
||||
$this->highlights = $highlights;
|
||||
}
|
||||
/**
|
||||
* Returns the shortcutpid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortcutpid()
|
||||
{
|
||||
return $this->shortcutpid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shortcutpid
|
||||
*
|
||||
* @param string $shortcutpid
|
||||
* @return void
|
||||
*/
|
||||
public function setShortcutpid ($shortcutpid)
|
||||
{
|
||||
$this->shortcutpid = $shortcutpid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shortcut
|
||||
*
|
||||
* @return bool $shortcut
|
||||
*/
|
||||
public function getShortcut()
|
||||
{
|
||||
return $this->shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shortcut
|
||||
*
|
||||
* @param bool $shortcut
|
||||
* @return void
|
||||
*/
|
||||
public function setShortcut($shortcut)
|
||||
{
|
||||
$this->shortcut = $shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the legacy
|
||||
*
|
||||
* @return bool $legacy
|
||||
*/
|
||||
public function getLegacy()
|
||||
{
|
||||
return $this->legacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the legacy
|
||||
*
|
||||
* @param bool $legacy
|
||||
* @return void
|
||||
*/
|
||||
public function setLegacy($legacy)
|
||||
{
|
||||
$this->legacy = $legacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the supportproduct
|
||||
*
|
||||
* @return bool $supportproduct
|
||||
*/
|
||||
public function getSupportproduct()
|
||||
{
|
||||
return $this->supportproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the supportproduct
|
||||
*
|
||||
* @param bool $supportproduct
|
||||
* @return void
|
||||
*/
|
||||
public function setSupportproduct($supportproduct)
|
||||
{
|
||||
$this->supportproduct = $supportproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subproduct
|
||||
*
|
||||
* @return bool $subproduct
|
||||
*/
|
||||
public function getSubproduct()
|
||||
{
|
||||
return $this->subproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subproduct
|
||||
*
|
||||
* @param bool $subproduct
|
||||
* @return void
|
||||
*/
|
||||
public function setSubproduct($subproduct)
|
||||
{
|
||||
$this->subproduct = $subproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the ObjectStorage for categories
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->categories = new ObjectStorage();
|
||||
$this->productimage = new ObjectStorage();
|
||||
$this->downloads = new ObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a category
|
||||
*
|
||||
* @param Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function addCategory(Category $category)
|
||||
{
|
||||
$this->categories->attach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a category
|
||||
*
|
||||
* @param Category $categoryToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeCategory(Category $categoryToRemove)
|
||||
{
|
||||
$this->categories->detach($categoryToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the categories
|
||||
*
|
||||
* @return ObjectStorage<Category>
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the categories
|
||||
*
|
||||
* @param ObjectStorage<Category> $categories
|
||||
* @return void
|
||||
*/
|
||||
public function setCategories(ObjectStorage $categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a product image
|
||||
*
|
||||
* @param FileReference $productimage
|
||||
* @return void
|
||||
*/
|
||||
public function addProductimage(FileReference $productimage)
|
||||
{
|
||||
$this->productimage->attach($productimage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a product image
|
||||
*
|
||||
* @param FileReference $productimageToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeProductimage(FileReference $productimageToRemove)
|
||||
{
|
||||
$this->productimage->detach($productimageToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product images
|
||||
*
|
||||
* @return ObjectStorage<FileReference>
|
||||
*/
|
||||
public function getProductimage()
|
||||
{
|
||||
return $this->productimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the product images
|
||||
*
|
||||
* @param ObjectStorage<FileReference> $productimage
|
||||
* @return void
|
||||
*/
|
||||
public function setProductimage(ObjectStorage $productimage)
|
||||
{
|
||||
$this->productimage = $productimage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a download
|
||||
*
|
||||
* @param \Evomedien\Vitec\Domain\Model\Download $download
|
||||
* @return void
|
||||
*/
|
||||
public function addDownload(\Evomedien\Vitec\Domain\Model\Download $download): void
|
||||
{
|
||||
$this->downloads->attach($download);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a download
|
||||
*
|
||||
* @param \Evomedien\Vitec\Domain\Model\Download $downloadToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeDownload(\Evomedien\Vitec\Domain\Model\Download $downloadToRemove): void
|
||||
{
|
||||
$this->downloads->detach($downloadToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the downloads
|
||||
*
|
||||
* @return ObjectStorage<\Evomedien\Vitec\Domain\Model\Download>
|
||||
*/
|
||||
public function getDownloads(): ObjectStorage
|
||||
{
|
||||
return $this->downloads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the downloads
|
||||
*
|
||||
* @param ObjectStorage<\Evomedien\Vitec\Domain\Model\Download> $downloads
|
||||
* @return void
|
||||
*/
|
||||
public function setDownloads(ObjectStorage $downloads): void
|
||||
{
|
||||
$this->downloads = $downloads;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Open Graph Image
|
||||
*
|
||||
* @return FileReference|null
|
||||
*/
|
||||
public function getOgimage(): ?FileReference
|
||||
{
|
||||
return $this->ogimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Open Graph Image
|
||||
*
|
||||
* @param FileReference $ogimage
|
||||
* @return void
|
||||
*/
|
||||
public function setOgimage(FileReference $ogimage): void
|
||||
{
|
||||
$this->ogimage = $ogimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content element link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentelement(): string
|
||||
{
|
||||
return $this->contentelement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content element link
|
||||
*
|
||||
* @param string $contentelement
|
||||
* @return void
|
||||
*/
|
||||
public function setContentelement(string $contentelement): void
|
||||
{
|
||||
$this->contentelement = $contentelement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content element cta link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentelementcta(): string
|
||||
{
|
||||
return $this->contentelementcta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content element link cta
|
||||
*
|
||||
* @param string $contentelementcta
|
||||
* @return void
|
||||
*/
|
||||
public function setContentelementcta(string $contentelementcta): void
|
||||
{
|
||||
$this->contentelementcta = $contentelementcta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Product>
|
||||
*/
|
||||
public function getRelatedprodukt(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
||||
{
|
||||
return $this->relatedprodukt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Product> $relatedprodukt
|
||||
*/
|
||||
public function setRelatedprodukt(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $relatedprodukt): void
|
||||
{
|
||||
$this->relatedprodukt = $relatedprodukt;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
}
|
||||
@@ -1,952 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This file is part of the "VITEC" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* (c) 2025
|
||||
*/
|
||||
|
||||
/**
|
||||
* Product
|
||||
*/
|
||||
class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* title
|
||||
*
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* slug
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $slug;
|
||||
|
||||
/**
|
||||
* urltitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $urltitle = '';
|
||||
|
||||
/**
|
||||
* seotitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $seotitle = '';
|
||||
|
||||
/**
|
||||
* seometa
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $seometa = '';
|
||||
|
||||
/**
|
||||
* keywords
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keywords = '';
|
||||
|
||||
/**
|
||||
* structureddata
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $structureddata = '';
|
||||
|
||||
/**
|
||||
* teaser
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $teaser = '';
|
||||
|
||||
/**
|
||||
* subtitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subtitle = '';
|
||||
|
||||
/**
|
||||
* video
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $video = '';
|
||||
|
||||
/**
|
||||
* hideonapp
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonapp = false;
|
||||
|
||||
/**
|
||||
* hideonwebsite
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonwebsite = false;
|
||||
|
||||
/**
|
||||
* hideondatasheets
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideondatasheets = false;
|
||||
|
||||
/**
|
||||
* hideonproducts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideonproducts = false;
|
||||
|
||||
/**
|
||||
* applications
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $applications = '';
|
||||
|
||||
/**
|
||||
* description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
|
||||
/**
|
||||
* highlights
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $highlights = '';
|
||||
|
||||
/**
|
||||
* shortcut
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shortcut = false;
|
||||
|
||||
/**
|
||||
* shortcutpid
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shortcutpid = '';
|
||||
|
||||
/**
|
||||
* legacy
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $legacy = false;
|
||||
|
||||
/**
|
||||
* supportproduct
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $supportproduct = false;
|
||||
|
||||
/**
|
||||
* subproduct
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $subproduct = false;
|
||||
|
||||
/**
|
||||
* @var ObjectStorage<Category>
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Product images
|
||||
*
|
||||
* @var ObjectStorage<FileReference>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $productimage;
|
||||
|
||||
/**
|
||||
* Downloads
|
||||
*
|
||||
* @var ObjectStorage<\Evomedien\Vitec\Domain\Model\Download>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $downloads;
|
||||
|
||||
|
||||
/**
|
||||
* Open Graph Image
|
||||
*
|
||||
* @var FileReference
|
||||
*/
|
||||
protected $ogimage;
|
||||
|
||||
/**
|
||||
* Content element link - Key Features
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
||||
/**
|
||||
* Uploaded / locally selected video file (FAL)
|
||||
*
|
||||
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference|null
|
||||
*/
|
||||
protected $videofile;
|
||||
|
||||
protected $contentelement;
|
||||
|
||||
/**
|
||||
* Content element link - CTA Features
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contentelementcta;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Evomedien\Vitec\Domain\Model\Product>
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
|
||||
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
|
||||
*/
|
||||
protected $relatedprodukt;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Returns the title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title
|
||||
*
|
||||
* @param string $title
|
||||
* @return void
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the video
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVideo()
|
||||
{
|
||||
return $this->video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the video
|
||||
*
|
||||
* @param string $video
|
||||
* @return void
|
||||
*/
|
||||
public function setVideo(string $video)
|
||||
{
|
||||
$this->video = $video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the slug
|
||||
*
|
||||
* @param string $slug
|
||||
* @return void
|
||||
*/
|
||||
public function setSlug(string $slug)
|
||||
{
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the urltitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrltitle()
|
||||
{
|
||||
return $this->urltitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the urltitle
|
||||
*
|
||||
* @param string $urltitle
|
||||
* @return void
|
||||
*/
|
||||
public function setUrltitle(string $urltitle)
|
||||
{
|
||||
$this->urltitle = $urltitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the seotitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSeotitle()
|
||||
{
|
||||
return $this->seotitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seotitle
|
||||
*
|
||||
* @param string $seotitle
|
||||
* @return void
|
||||
*/
|
||||
public function setSeotitle(string $seotitle)
|
||||
{
|
||||
$this->seotitle = $seotitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the seometa
|
||||
*
|
||||
* @return string $seometa
|
||||
*/
|
||||
public function getSeometa()
|
||||
{
|
||||
return $this->seometa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seometa
|
||||
*
|
||||
* @param string $seometa
|
||||
* @return void
|
||||
*/
|
||||
public function setSeometa($seometa)
|
||||
{
|
||||
$this->seometa = $seometa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keywords
|
||||
*
|
||||
* @return string $keywords
|
||||
*/
|
||||
public function getKeywords()
|
||||
{
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the keywords
|
||||
*
|
||||
* @param string $keywords
|
||||
* @return void
|
||||
*/
|
||||
public function setKeywords($keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teaser
|
||||
*
|
||||
* @return string $kteasereywords
|
||||
*/
|
||||
public function getTeaser()
|
||||
{
|
||||
return $this->teaser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the teaser
|
||||
*
|
||||
* @param string $teaser
|
||||
* @return void
|
||||
*/
|
||||
public function setTeaser($teaser)
|
||||
{
|
||||
$this->teaser = $teaser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subtitle
|
||||
*
|
||||
* @return string $subtitle
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
return $this->subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subtitle
|
||||
*
|
||||
* @param string $subtitle
|
||||
* @return void
|
||||
*/
|
||||
public function setSubtitle($subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonapp
|
||||
*
|
||||
* @return bool $hideonapp
|
||||
*/
|
||||
public function getHideonapp()
|
||||
{
|
||||
return $this->hideonapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonapp
|
||||
*
|
||||
* @param bool $hideonapp
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonapp($hideonapp)
|
||||
{
|
||||
$this->hideonapp = $hideonapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description
|
||||
*
|
||||
* @return bool $description
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description
|
||||
*
|
||||
* @param bool $description
|
||||
* @return void
|
||||
*/
|
||||
public function setDescriptionp($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonwebsite
|
||||
*
|
||||
* @return bool $hideonwebsite
|
||||
*/
|
||||
public function getHideonwebsite()
|
||||
{
|
||||
return $this->hideonwebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonwebsite
|
||||
*
|
||||
* @param bool $hideonwebsite
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonwebsite($hideonwebsite)
|
||||
{
|
||||
$this->hideonwebsite = $hideonwebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideondatasheets
|
||||
*
|
||||
* @return bool $hideondatasheets
|
||||
*/
|
||||
public function getHideondatasheets()
|
||||
{
|
||||
return $this->hideondatasheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideondatasheets
|
||||
*
|
||||
* @param bool $hideondatasheets
|
||||
* @return void
|
||||
*/
|
||||
public function setHideondatasheets($hideondatasheets)
|
||||
{
|
||||
$this->hideondatasheets = $hideondatasheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hideonproducts
|
||||
*
|
||||
* @return bool $hideonproducts
|
||||
*/
|
||||
public function getHideonproducts()
|
||||
{
|
||||
return $this->hideonproducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hideonproducts
|
||||
*
|
||||
* @param bool $hideonproducts
|
||||
* @return void
|
||||
*/
|
||||
public function setHideonproducts($hideonproducts)
|
||||
{
|
||||
$this->hideonproducts = $hideonproducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the structureddata
|
||||
*
|
||||
* @return string $structureddata
|
||||
*/
|
||||
public function getStructureddata()
|
||||
{
|
||||
return $this->structureddata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the structureddata
|
||||
*
|
||||
* @param string $structureddata
|
||||
* @return void
|
||||
*/
|
||||
public function setStructureddata($structureddata)
|
||||
{
|
||||
$this->structureddata = $structureddata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the applications
|
||||
*
|
||||
* @return string $applications
|
||||
*/
|
||||
public function getApplications()
|
||||
{
|
||||
return $this->applications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the applications
|
||||
*
|
||||
* @param string $applications
|
||||
* @return void
|
||||
*/
|
||||
public function setApplications($applications)
|
||||
{
|
||||
$this->applications = $applications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highlights
|
||||
*
|
||||
* @return string $highlights
|
||||
*/
|
||||
public function getHighlights()
|
||||
{
|
||||
return $this->highlights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the highlights
|
||||
*
|
||||
* @param string $highlights
|
||||
* @return void
|
||||
*/
|
||||
public function setHighlights($highlights)
|
||||
{
|
||||
$this->highlights = $highlights;
|
||||
}
|
||||
/**
|
||||
* Returns the shortcutpid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortcutpid()
|
||||
{
|
||||
return $this->shortcutpid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shortcutpid
|
||||
*
|
||||
* @param string $shortcutpid
|
||||
* @return void
|
||||
*/
|
||||
public function setShortcutpid ($shortcutpid)
|
||||
{
|
||||
$this->shortcutpid = $shortcutpid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shortcut
|
||||
*
|
||||
* @return bool $shortcut
|
||||
*/
|
||||
public function getShortcut()
|
||||
{
|
||||
return $this->shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shortcut
|
||||
*
|
||||
* @param bool $shortcut
|
||||
* @return void
|
||||
*/
|
||||
public function setShortcut($shortcut)
|
||||
{
|
||||
$this->shortcut = $shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the legacy
|
||||
*
|
||||
* @return bool $legacy
|
||||
*/
|
||||
public function getLegacy()
|
||||
{
|
||||
return $this->legacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the legacy
|
||||
*
|
||||
* @param bool $legacy
|
||||
* @return void
|
||||
*/
|
||||
public function setLegacy($legacy)
|
||||
{
|
||||
$this->legacy = $legacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the supportproduct
|
||||
*
|
||||
* @return bool $supportproduct
|
||||
*/
|
||||
public function getSupportproduct()
|
||||
{
|
||||
return $this->supportproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the supportproduct
|
||||
*
|
||||
* @param bool $supportproduct
|
||||
* @return void
|
||||
*/
|
||||
public function setSupportproduct($supportproduct)
|
||||
{
|
||||
$this->supportproduct = $supportproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subproduct
|
||||
*
|
||||
* @return bool $subproduct
|
||||
*/
|
||||
public function getSubproduct()
|
||||
{
|
||||
return $this->subproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subproduct
|
||||
*
|
||||
* @param bool $subproduct
|
||||
* @return void
|
||||
*/
|
||||
public function setSubproduct($subproduct)
|
||||
{
|
||||
$this->subproduct = $subproduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the ObjectStorage for categories
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->categories = new ObjectStorage();
|
||||
$this->productimage = new ObjectStorage();
|
||||
$this->downloads = new ObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a category
|
||||
*
|
||||
* @param Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function addCategory(Category $category)
|
||||
{
|
||||
$this->categories->attach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a category
|
||||
*
|
||||
* @param Category $categoryToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeCategory(Category $categoryToRemove)
|
||||
{
|
||||
$this->categories->detach($categoryToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the categories
|
||||
*
|
||||
* @return ObjectStorage<Category>
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the categories
|
||||
*
|
||||
* @param ObjectStorage<Category> $categories
|
||||
* @return void
|
||||
*/
|
||||
public function setCategories(ObjectStorage $categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a product image
|
||||
*
|
||||
* @param FileReference $productimage
|
||||
* @return void
|
||||
*/
|
||||
public function addProductimage(FileReference $productimage)
|
||||
{
|
||||
$this->productimage->attach($productimage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a product image
|
||||
*
|
||||
* @param FileReference $productimageToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeProductimage(FileReference $productimageToRemove)
|
||||
{
|
||||
$this->productimage->detach($productimageToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product images
|
||||
*
|
||||
* @return ObjectStorage<FileReference>
|
||||
*/
|
||||
public function getProductimage()
|
||||
{
|
||||
return $this->productimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the product images
|
||||
*
|
||||
* @param ObjectStorage<FileReference> $productimage
|
||||
* @return void
|
||||
*/
|
||||
public function setProductimage(ObjectStorage $productimage)
|
||||
{
|
||||
$this->productimage = $productimage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a download
|
||||
*
|
||||
* @param \Evomedien\Vitec\Domain\Model\Download $download
|
||||
* @return void
|
||||
*/
|
||||
public function addDownload(\Evomedien\Vitec\Domain\Model\Download $download): void
|
||||
{
|
||||
$this->downloads->attach($download);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a download
|
||||
*
|
||||
* @param \Evomedien\Vitec\Domain\Model\Download $downloadToRemove
|
||||
* @return void
|
||||
*/
|
||||
public function removeDownload(\Evomedien\Vitec\Domain\Model\Download $downloadToRemove): void
|
||||
{
|
||||
$this->downloads->detach($downloadToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the downloads
|
||||
*
|
||||
* @return ObjectStorage<\Evomedien\Vitec\Domain\Model\Download>
|
||||
*/
|
||||
public function getDownloads(): ObjectStorage
|
||||
{
|
||||
return $this->downloads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the downloads
|
||||
*
|
||||
* @param ObjectStorage<\Evomedien\Vitec\Domain\Model\Download> $downloads
|
||||
* @return void
|
||||
*/
|
||||
public function setDownloads(ObjectStorage $downloads): void
|
||||
{
|
||||
$this->downloads = $downloads;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Open Graph Image
|
||||
*
|
||||
* @return FileReference|null
|
||||
*/
|
||||
public function getOgimage(): ?FileReference
|
||||
{
|
||||
return $this->ogimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Open Graph Image
|
||||
*
|
||||
* @param FileReference $ogimage
|
||||
* @return void
|
||||
*/
|
||||
public function setOgimage(FileReference $ogimage): void
|
||||
{
|
||||
$this->ogimage = $ogimage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content element link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the uploaded video file
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference|null
|
||||
*/
|
||||
public function getVideofile(): ?\TYPO3\CMS\Extbase\Domain\Model\FileReference
|
||||
{
|
||||
return $this->videofile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the uploaded video file
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference|null $videofile
|
||||
* @return void
|
||||
*/
|
||||
public function setVideofile(?\TYPO3\CMS\Extbase\Domain\Model\FileReference $videofile): void
|
||||
{
|
||||
$this->videofile = $videofile;
|
||||
}
|
||||
|
||||
public function getContentelement(): string
|
||||
{
|
||||
return $this->contentelement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content element link
|
||||
*
|
||||
* @param string $contentelement
|
||||
* @return void
|
||||
*/
|
||||
public function setContentelement(string $contentelement): void
|
||||
{
|
||||
$this->contentelement = $contentelement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content element cta link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentelementcta(): string
|
||||
{
|
||||
return $this->contentelementcta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content element link cta
|
||||
*
|
||||
* @param string $contentelementcta
|
||||
* @return void
|
||||
*/
|
||||
public function setContentelementcta(string $contentelementcta): void
|
||||
{
|
||||
$this->contentelementcta = $contentelementcta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Product>
|
||||
*/
|
||||
public function getRelatedprodukt(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
||||
{
|
||||
return $this->relatedprodukt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Product> $relatedprodukt
|
||||
*/
|
||||
public function setRelatedprodukt(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $relatedprodukt): void
|
||||
{
|
||||
$this->relatedprodukt = $relatedprodukt;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
}
|
||||
Executable → Regular
File mode changed.
Executable → Regular
File mode changed.
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$listType];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+32
-16
@@ -68,10 +68,12 @@ final class ContentElementResolver
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms:
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (page links etc.)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
@@ -155,33 +157,47 @@ final class ContentElementResolver
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
if (!str_starts_with($link, 't3://record')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (empty($parts['query'])) {
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
|
||||
if ($identifier !== 'tt_content' || $uid <= 0) {
|
||||
return 0;
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
return $uid;
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
if ($listType === '' || !isset(self::PLUGIN_RENDERERS[$listType])) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$listType];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\Service;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardcollectionJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
* Product.contentelement / Product.contentelementcta) to the JSON
|
||||
* representation of the referenced tt_content element.
|
||||
*
|
||||
* Mirrors the shape produced by
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}:
|
||||
* { id, type, colPos, sorting, appearance, data }
|
||||
*
|
||||
* Nested VITEC list-plugins are resolved through their `renderForRecord()`
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
final class ContentElementResolver
|
||||
{
|
||||
/** Fields that go to the envelope (not to `data`). */
|
||||
private const ENVELOPE = [
|
||||
'uid', 'CType', 'colPos', 'sorting',
|
||||
'layout', 'frame_class', 'space_before_class', 'space_after_class',
|
||||
];
|
||||
|
||||
/** Technical / system / TCA-default fields — never sent to frontend. */
|
||||
private const SYSTEM_FIELDS = [
|
||||
'pid', 'sys_language_uid', 'l18n_parent', 'l18n_diffsource',
|
||||
'l10n_source', 'l10n_state', 'l10n_parent',
|
||||
't3_origuid', 'tx_impexp_origuid',
|
||||
'tx_container_parent',
|
||||
'tstamp', 'crdate', 'cruser_id',
|
||||
'hidden', 'deleted', 'starttime', 'endtime', 'fe_group',
|
||||
't3ver_oid', 't3ver_wsid', 't3ver_state', 't3ver_stage',
|
||||
't3ver_id', 't3ver_label', 't3ver_count', 't3ver_tstamp',
|
||||
'editlock', 'sorting_foreign', 'rowDescription',
|
||||
'spaceBefore', 'spaceAfter',
|
||||
'imagecols', 'sectionIndex', 'linkToTop', 'recursive', 'date',
|
||||
'bullets_type', 'cols',
|
||||
'table_delimiter', 'table_enclosure', 'table_header_position',
|
||||
'table_tfoot', 'table_caption',
|
||||
'filelink_size', 'filelink_sorting', 'filelink_sorting_direction',
|
||||
'uploads_description', 'uploads_type',
|
||||
];
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a typolink string to a normalised tt_content JSON element.
|
||||
*
|
||||
* Accepted forms (all may include an optional anchor fragment):
|
||||
* - "t3://record?identifier=tt_content&uid=N"
|
||||
* - "t3://page?uid=PAGE#N" (link-popup: pick a CE on a page;
|
||||
* the fragment is the tt_content uid)
|
||||
* - "<numeric>" (legacy: bare tt_content uid)
|
||||
* - everything else → null (pure page links etc.)
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function resolveLink(?string $link): ?array
|
||||
{
|
||||
try {
|
||||
$link = trim((string)$link);
|
||||
if ($link === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uid = self::extractTtContentUid($link);
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$row = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a tt_content DB row to the same envelope shape that
|
||||
* {@see \Evomedien\Vitec\DataProcessing\ContainerChildrenProcessor}
|
||||
* emits for container children. VITEC list-plugin children are
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
if (in_array($field, self::ENVELOPE, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
$data[$field] = self::castValue($field, $value);
|
||||
}
|
||||
|
||||
self::resolvePluginData($record, $data);
|
||||
|
||||
return [
|
||||
'id' => (int)$record['uid'],
|
||||
'type' => (string)$record['CType'],
|
||||
'colPos' => (int)($record['colPos'] ?? 0),
|
||||
'sorting' => (int)($record['sorting'] ?? 0),
|
||||
'appearance' => [
|
||||
'layout' => (string)($record['layout'] ?? ''),
|
||||
'frameClass' => (string)($record['frame_class'] ?? 'default'),
|
||||
'spaceBefore' => (string)($record['space_before_class'] ?? ''),
|
||||
'spaceAfter' => (string)($record['space_after_class'] ?? ''),
|
||||
],
|
||||
'data' => (object)$data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the tt_content uid from a typolink string.
|
||||
*
|
||||
* Handles four forms:
|
||||
* 1. plain numeric → tt_content uid
|
||||
* 2. t3://record?identifier=tt_content&uid=N → uid N
|
||||
* 3. t3://record?identifier=tt_content&uid=N#X → uid N (anchor ignored)
|
||||
* 4. t3://page?uid=PAGE#N → uid N from fragment
|
||||
* (link-popup picks a content element on a page; the fragment is
|
||||
* the tt_content uid, the query is the page uid)
|
||||
*/
|
||||
private static function extractTtContentUid(string $link): int
|
||||
{
|
||||
// Form 1: bare numeric uid
|
||||
if (ctype_digit($link)) {
|
||||
return (int)$link;
|
||||
}
|
||||
|
||||
$parts = parse_url($link);
|
||||
if (!is_array($parts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forms 2 & 3: t3://record?identifier=tt_content&uid=N
|
||||
if (str_starts_with($link, 't3://record') && !empty($parts['query'])) {
|
||||
$params = [];
|
||||
parse_str((string)$parts['query'], $params);
|
||||
$identifier = (string)($params['identifier'] ?? '');
|
||||
$uid = (int)($params['uid'] ?? 0);
|
||||
if ($identifier === 'tt_content' && $uid > 0) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Form 4: t3://page?uid=PAGE#N → tt_content uid lives in the fragment
|
||||
if (str_starts_with($link, 't3://page')) {
|
||||
$fragment = (string)($parts['fragment'] ?? '');
|
||||
if (ctype_digit($fragment)) {
|
||||
return (int)$fragment;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the record is a VITEC list-plugin, run its renderer for THIS row
|
||||
* and inject the decoded result under its key. Drops raw pi_flexform.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = $renderer->renderForRecord($record);
|
||||
if ($json === '' || $json === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$jsonKey] = $decoded;
|
||||
unset($data['pi_flexform']);
|
||||
} catch (\Throwable $e) {
|
||||
// leave raw data on failure
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
}
|
||||
|
||||
private static function castValue(string $field, mixed $value): mixed
|
||||
{
|
||||
if (in_array($field, ['header_layout'], true)) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+16
-2
@@ -9,6 +9,11 @@ use Evomedien\Vitec\UserFunc\ProductListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ProductShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseListJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\UsecaseShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\MarketShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\SolutionShowJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DownloadcardcollectionJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\DatasheetsJsonRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
@@ -63,6 +68,11 @@ final class ContentElementResolver
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
'vitec_usecaselist' => [UsecaseListJsonRenderer::class, 'usecases'],
|
||||
'vitec_usecaseshow' => [UsecaseShowJsonRenderer::class, 'usecase'],
|
||||
'vitec_marketshow' => [MarketShowJsonRenderer::class, 'market'],
|
||||
'vitec_solutionshow' => [SolutionShowJsonRenderer::class, 'solution'],
|
||||
'vitec_downloadcard' => [DownloadcardJsonRenderer::class, 'downloadcard'],
|
||||
'vitec_downloadcardcollection' => [DownloadcardcollectionJsonRenderer::class, 'downloadcardcollection'],
|
||||
'vitec_datasheets' => [DatasheetsJsonRenderer::class, 'datasheets'],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -209,13 +219,17 @@ final class ContentElementResolver
|
||||
*/
|
||||
private static function resolvePluginData(array $record, array &$data): void
|
||||
{
|
||||
// v14: plugins are their own CType; legacy elements still carry list_type.
|
||||
$cType = (string)($record['CType'] ?? '');
|
||||
$listType = (string)($record['list_type'] ?? '');
|
||||
if ($listType === '' || !isset(self::PLUGIN_RENDERERS[$listType])) {
|
||||
$key = isset(self::PLUGIN_RENDERERS[$cType]) ? $cType
|
||||
: (isset(self::PLUGIN_RENDERERS[$listType]) ? $listType : null);
|
||||
if ($key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$listType];
|
||||
[$rendererClass, $jsonKey] = self::PLUGIN_RENDERERS[$key];
|
||||
$renderer = GeneralUtility::makeInstance($rendererClass);
|
||||
|
||||
if (!method_exists($renderer, 'renderForRecord')) {
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render the Datasheets plugin as JSON.
|
||||
*
|
||||
* Lists every product that has at least one datasheet, with the LATEST
|
||||
* datasheet attached. "Datasheet" = a Download linked to the product via
|
||||
* tx_vitec_product_download_mm with hideondatasheets = 0. "Latest" is
|
||||
* the download with the highest tstamp.
|
||||
*
|
||||
* The plugin is global — the page on which it is placed is not used as
|
||||
* a filter. FlexForm settings (showFilter, showSearch, itemsPerPage)
|
||||
* are passed through for the frontend UI to honour.
|
||||
*
|
||||
* Exception-safe. Returns '' on failure / nothing to render.
|
||||
*/
|
||||
class DatasheetsJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
|
||||
$pageId = 0;
|
||||
$req = $GLOBALS["TYPO3_REQUEST"] ?? null;
|
||||
if ($req !== null) {
|
||||
$pi = $req->getAttribute("frontend.page.information");
|
||||
if ($pi !== null) { $pageId = (int)$pi->getId(); }
|
||||
}
|
||||
if ($pageId <= 0) { $pageId = (int)($GLOBALS["TSFE"]->id ?? 0); }
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$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_datasheets', ParameterType::STRING)),
|
||||
$qb->expr()->and(
|
||||
$qb->expr()->eq('CType', $qb->createNamedParameter('list', ParameterType::STRING)),
|
||||
$qb->expr()->eq('CType', $qb->createNamedParameter('vitec_datasheets', ParameterType::STRING))
|
||||
)
|
||||
),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($rows)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($rows[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'] ?? [];
|
||||
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
$settingsOut = [
|
||||
'showFilter' => (bool)($settings['showFilter'] ?? true),
|
||||
'showSearch' => (bool)($settings['showSearch'] ?? true),
|
||||
'itemsPerPage' => (int)($settings['itemsPerPage'] ?? 20),
|
||||
];
|
||||
|
||||
// 1) Pull all (product_uid, latest_datasheet_uid) pairs in one query.
|
||||
// GROUP BY product, take MAX(tstamp) → join back to get that exact download.
|
||||
$items = $this->fetchProductLatestDatasheetPairs();
|
||||
|
||||
// 2) Hydrate each pair: full product + full datasheet objects.
|
||||
$itemsOut = [];
|
||||
foreach ($items as $pair) {
|
||||
$productUid = (int)$pair['product_uid'];
|
||||
$datasheetUid = (int)$pair['datasheet_uid'];
|
||||
|
||||
$product = $this->fetchProduct($productUid);
|
||||
$datasheet = $this->fetchDownload($datasheetUid);
|
||||
if (!$product || !$datasheet) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$itemsOut[] = [
|
||||
'product' => $this->serializeProduct($product),
|
||||
'datasheet' => $this->serializeDatasheet($datasheet),
|
||||
];
|
||||
}
|
||||
|
||||
$response = [
|
||||
'items' => $itemsOut,
|
||||
'settings' => $settingsOut,
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'productCount' => count($itemsOut),
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For each visible product that has at least one visible datasheet,
|
||||
* return [product_uid => latest_datasheet_uid]. Sorted by product title.
|
||||
*
|
||||
* @return array<int,array{product_uid:int,datasheet_uid:int}>
|
||||
*/
|
||||
private function fetchProductLatestDatasheetPairs(): array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_product_download_mm');
|
||||
$expr = $qb->expr();
|
||||
|
||||
// Inner aggregation: for each product, the latest download tstamp.
|
||||
// We use a single query with JOIN on the same (mm + download) to resolve
|
||||
// the actual download_uid matching MAX(tstamp). Approach: do it in two
|
||||
// simple steps to stay SQL-portable.
|
||||
|
||||
// Step A: gather all candidate (product_uid, download_uid, tstamp) tuples.
|
||||
$rows = $qb
|
||||
->select(
|
||||
'mm.uid_local AS product_uid',
|
||||
'mm.uid_foreign AS datasheet_uid',
|
||||
'd.tstamp AS d_tstamp',
|
||||
'p.title AS p_title'
|
||||
)
|
||||
->from('tx_vitec_product_download_mm', 'mm')
|
||||
->join('mm', 'tx_vitec_domain_model_download', 'd', 'd.uid = mm.uid_foreign')
|
||||
->join('mm', 'tx_vitec_domain_model_product', 'p', 'p.uid = mm.uid_local')
|
||||
->where(
|
||||
$expr->eq('d.deleted', 0),
|
||||
$expr->eq('d.hidden', 0),
|
||||
$expr->eq('d.hideonwebsite', 0),
|
||||
$expr->eq('d.hideondatasheets', 0),
|
||||
$expr->eq('p.deleted', 0),
|
||||
$expr->eq('p.hidden', 0),
|
||||
$expr->eq('p.hideonwebsite', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
// Step B: reduce to {product_uid => latest datasheet} in PHP.
|
||||
$latestPerProduct = []; // product_uid => [datasheet_uid, tstamp, title]
|
||||
foreach ($rows as $r) {
|
||||
$pUid = (int)$r['product_uid'];
|
||||
$dUid = (int)$r['datasheet_uid'];
|
||||
$ts = (int)$r['d_tstamp'];
|
||||
$title = (string)$r['p_title'];
|
||||
|
||||
if (!isset($latestPerProduct[$pUid]) || $ts > $latestPerProduct[$pUid]['tstamp']) {
|
||||
$latestPerProduct[$pUid] = [
|
||||
'product_uid' => $pUid,
|
||||
'datasheet_uid' => $dUid,
|
||||
'tstamp' => $ts,
|
||||
'title' => $title,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by product title ASC.
|
||||
usort($latestPerProduct, static fn($a, $b) => strcasecmp($a['title'], $b['title']));
|
||||
|
||||
// Strip helper fields.
|
||||
return array_map(
|
||||
static fn($r) => ['product_uid' => $r['product_uid'], 'datasheet_uid' => $r['datasheet_uid']],
|
||||
$latestPerProduct
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|false
|
||||
*/
|
||||
private function fetchProduct(int $uid)
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
return $qb
|
||||
->select('uid', 'title', 'slug', 'subtitle', 'teaser')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|false
|
||||
*/
|
||||
private function fetchDownload(int $uid)
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
return $qb
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_download')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
'image' => $this->getProductFirstImage($uid),
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $download
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function serializeDatasheet(array $download): array
|
||||
{
|
||||
$uid = (int)$download['uid'];
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($download['title'] ?? ''),
|
||||
'slug' => (string)($download['slug'] ?? ''),
|
||||
'teaser' => (string)($download['teaser'] ?? ''),
|
||||
'description' => (string)($download['description'] ?? ''),
|
||||
'tstamp' => (int)($download['tstamp'] ?? 0),
|
||||
'file' => $this->getDownloadFile($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
private function getProductFirstImage(int $productUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $qb
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$qb->expr()->eq('sfr.tablenames', $qb->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$qb->expr()->eq('sfr.fieldname', $qb->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$qb->expr()->eq('sfr.uid_foreign', $qb->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('sfr.deleted', 0),
|
||||
$qb->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$default = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 400, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($default),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function getProductCategories(int $productUid): array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $qb
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->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_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$qb->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$qb->expr()->eq('mm.uid_foreign', $qb->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('c.deleted', 0),
|
||||
$qb->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => (string)($cat['title'] ?? ''),
|
||||
'description' => (string)($cat['description'] ?? ''),
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
private function getDownloadFile(int $downloadUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $qb
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid AS file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$qb->expr()->eq('fr.tablenames', $qb->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.fieldname', $qb->createNamedParameter('file', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.uid_foreign', $qb->createNamedParameter($downloadUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('fr.deleted', 0),
|
||||
$qb->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* UserFunc to render the Downloadcard plugin as JSON for headless output.
|
||||
*
|
||||
* Behaviour:
|
||||
* - settings.download set -> single download object (key: "download")
|
||||
* - else settings.product set -> all downloads of that product (key: "downloads",
|
||||
* plus a small "product" context)
|
||||
* - neither -> empty (key removed by headless ifEmptyUnsetKey)
|
||||
*
|
||||
* `settings.layout` / magstyle / magheader / magtext / maglink / adddetaillink
|
||||
* are always passed through under the "settings" block for the frontend.
|
||||
*
|
||||
* `render()` performs page discovery; `renderForRecord()` processes a specific
|
||||
* tt_content row and is reused by ContainerChildrenProcessor /
|
||||
* ContentElementResolver. Exception-safe.
|
||||
*/
|
||||
class DownloadcardJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
|
||||
$pageId = 0;
|
||||
$req = $GLOBALS["TYPO3_REQUEST"] ?? null;
|
||||
if ($req !== null) {
|
||||
$pi = $req->getAttribute("frontend.page.information");
|
||||
if ($pi !== null) { $pageId = (int)$pi->getId(); }
|
||||
}
|
||||
if ($pageId <= 0) { $pageId = (int)($GLOBALS["TSFE"]->id ?? 0); }
|
||||
|
||||
$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('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($rows)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($rows[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$downloadUid = (int)($settings['download'] ?? 0);
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// Settings always carried through to the frontend
|
||||
$settingsOut = [
|
||||
'layout' => (string)($settings['layout'] ?? ''),
|
||||
'magstyle' => (bool)($settings['magstyle'] ?? false),
|
||||
'magheader' => (string)($settings['magheader'] ?? ''),
|
||||
'magtext' => (string)($settings['magtext'] ?? ''),
|
||||
'maglink' => (string)($settings['maglink'] ?? ''),
|
||||
'adddetaillink' => (bool)($settings['adddetaillink'] ?? false),
|
||||
];
|
||||
|
||||
// --- Mode 1: single download ---
|
||||
if ($downloadUid > 0) {
|
||||
$download = $this->fetchDownload($downloadUid);
|
||||
if (!$download) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Download not found', 'debug' => ['downloadUid' => $downloadUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'mode' => 'single',
|
||||
'download' => $this->serializeDownload($download),
|
||||
'settings' => $settingsOut,
|
||||
];
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId, 'downloadUid' => $downloadUid, 'settings' => $settings,
|
||||
];
|
||||
}
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
// --- Mode 2: all downloads of a product ---
|
||||
if ($productUid > 0) {
|
||||
$downloads = $this->fetchDownloadsForProduct($productUid);
|
||||
$product = $this->fetchProductContext($productUid);
|
||||
|
||||
$response = [
|
||||
'mode' => 'product-downloads',
|
||||
'product' => $product,
|
||||
'downloads' => array_map(fn($r) => $this->serializeDownload($r), $downloads),
|
||||
'settings' => $settingsOut,
|
||||
];
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'downloadCount' => count($downloads),
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
// Neither selected: nothing to render.
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No download or product selected', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|false
|
||||
*/
|
||||
private function fetchDownload(int $uid)
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
return $qb
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_download')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($uid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0),
|
||||
$qb->expr()->eq('hideonwebsite', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
private function fetchDownloadsForProduct(int $productUid): array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
return $qb
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join('d', 'tx_vitec_product_download_mm', 'mm', 'mm.uid_foreign = d.uid')
|
||||
->where(
|
||||
$qb->expr()->eq('mm.uid_local', $qb->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('d.deleted', 0),
|
||||
$qb->expr()->eq('d.hidden', 0),
|
||||
$qb->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
private function fetchProductContext(int $productUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$row = $qb
|
||||
->select('uid', 'title', 'slug', 'subtitle', 'teaser')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$qb->expr()->eq('uid', $qb->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['uid'],
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'slug' => (string)($row['slug'] ?? ''),
|
||||
'subtitle' => (string)($row['subtitle'] ?? ''),
|
||||
'teaser' => (string)($row['teaser'] ?? ''),
|
||||
'link' => '/product/' . (string)($row['slug'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $download
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeDownload(array $download): array
|
||||
{
|
||||
$uid = (int)$download['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($download['title'] ?? ''),
|
||||
'slug' => (string)($download['slug'] ?? ''),
|
||||
'teaser' => (string)($download['teaser'] ?? ''),
|
||||
'description' => (string)($download['description'] ?? ''),
|
||||
'keywords' => (string)($download['keywords'] ?? ''),
|
||||
'icon' => (string)($download['icon'] ?? ''),
|
||||
'filepath' => (string)($download['filepath'] ?? ''),
|
||||
'fileprefix' => (string)($download['fileprefix'] ?? ''),
|
||||
'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),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the FAL file reference (fieldname=file) for a download.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getDownloadFile(int $downloadUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $qb
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid AS file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$qb->expr()->eq('fr.tablenames', $qb->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.fieldname', $qb->createNamedParameter('file', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.uid_foreign', $qb->createNamedParameter($downloadUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('fr.deleted', 0),
|
||||
$qb->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render the Downloadcardcollection plugin as JSON.
|
||||
*
|
||||
* FlexForm-driven (no controller action):
|
||||
* - settings.download : comma-separated tx_vitec_domain_model_download UIDs
|
||||
* (selectMultipleSideBySide).
|
||||
* - settings.image : optional header image (inline FAL on the
|
||||
* tt_content row, fieldname=image).
|
||||
* - settings.layout / magstyle / magheader / magtext / maglink / adddetaillink
|
||||
* are passed through under "settings".
|
||||
*
|
||||
* Exception-safe. Returns '' when nothing to render.
|
||||
*/
|
||||
class DownloadcardcollectionJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
|
||||
$pageId = 0;
|
||||
$req = $GLOBALS["TYPO3_REQUEST"] ?? null;
|
||||
if ($req !== null) {
|
||||
$pi = $req->getAttribute("frontend.page.information");
|
||||
if ($pi !== null) { $pageId = (int)$pi->getId(); }
|
||||
}
|
||||
if ($pageId <= 0) { $pageId = (int)($GLOBALS["TSFE"]->id ?? 0); }
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$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_downloadcardcollection', ParameterType::STRING)),
|
||||
$qb->expr()->and(
|
||||
$qb->expr()->eq('CType', $qb->createNamedParameter('list', ParameterType::STRING)),
|
||||
$qb->expr()->eq('CType', $qb->createNamedParameter('vitec_downloadcardcollection', ParameterType::STRING))
|
||||
)
|
||||
),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($rows)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($rows[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$ttContentUid = (int)($contentElement['uid'] ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// Pass-through settings for the frontend
|
||||
$settingsOut = [
|
||||
'layout' => (string)($settings['layout'] ?? ''),
|
||||
'magstyle' => (bool)($settings['magstyle'] ?? false),
|
||||
'magheader' => (string)($settings['magheader'] ?? ''),
|
||||
'magtext' => (string)($settings['magtext'] ?? ''),
|
||||
'maglink' => (string)($settings['maglink'] ?? ''),
|
||||
'adddetaillink' => (bool)($settings['adddetaillink'] ?? false),
|
||||
];
|
||||
|
||||
// --- Downloads: comma-separated UID list from settings.download ---
|
||||
$downloadUids = $this->parseUidList($settings['download'] ?? '');
|
||||
$downloads = $downloadUids === [] ? [] : $this->fetchDownloadsByUids($downloadUids);
|
||||
|
||||
// --- Header image (inline FAL on this tt_content element, fieldname=image) ---
|
||||
$image = $this->getCollectionImage($ttContentUid);
|
||||
|
||||
$response = [
|
||||
'image' => $image,
|
||||
'downloads' => array_map(fn($r) => $this->serializeDownload($r), $downloads),
|
||||
'settings' => $settingsOut,
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'ttContentUid' => $ttContentUid,
|
||||
'downloadUids' => $downloadUids,
|
||||
'downloadCount' => count($downloads),
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts "5,7,12" or "5,,7" or even an array-like value. Returns int[].
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function parseUidList(mixed $raw): array
|
||||
{
|
||||
if (is_array($raw)) {
|
||||
$raw = implode(',', $raw);
|
||||
}
|
||||
$raw = (string)$raw;
|
||||
if ($raw === '') {
|
||||
return [];
|
||||
}
|
||||
$uids = array_filter(array_map('intval', explode(',', $raw)), static fn(int $u) => $u > 0);
|
||||
return array_values(array_unique($uids));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $uids
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
private function fetchDownloadsByUids(array $uids): array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$rows = $qb
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_download')
|
||||
->where(
|
||||
$qb->expr()->in('uid', $qb->createNamedParameter($uids, Connection::PARAM_INT_ARRAY)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0),
|
||||
$qb->expr()->eq('hideonwebsite', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
// Preserve the editor-defined order from $uids
|
||||
$orderMap = array_flip($uids);
|
||||
usort($rows, static function ($a, $b) use ($orderMap) {
|
||||
return ($orderMap[(int)$a['uid']] ?? PHP_INT_MAX) <=> ($orderMap[(int)$b['uid']] ?? PHP_INT_MAX);
|
||||
});
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the inline FAL header image stored on this tt_content row
|
||||
* (tablenames='tt_content', fieldname='image').
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
private function getCollectionImage(int $ttContentUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $qb
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$qb->expr()->eq('sfr.tablenames', $qb->createNamedParameter('tt_content', ParameterType::STRING)),
|
||||
$qb->expr()->eq('sfr.fieldname', $qb->createNamedParameter('image', ParameterType::STRING)),
|
||||
$qb->expr()->eq('sfr.uid_foreign', $qb->createNamedParameter($ttContentUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('sfr.deleted', 0),
|
||||
$qb->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$variant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($variant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$default = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($default),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $download
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeDownload(array $download): array
|
||||
{
|
||||
$uid = (int)$download['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($download['title'] ?? ''),
|
||||
'slug' => (string)($download['slug'] ?? ''),
|
||||
'teaser' => (string)($download['teaser'] ?? ''),
|
||||
'description' => (string)($download['description'] ?? ''),
|
||||
'keywords' => (string)($download['keywords'] ?? ''),
|
||||
'icon' => (string)($download['icon'] ?? ''),
|
||||
'filepath' => (string)($download['filepath'] ?? ''),
|
||||
'fileprefix' => (string)($download['fileprefix'] ?? ''),
|
||||
'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),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the FAL file reference (fieldname=file) for a download.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getDownloadFile(int $downloadUid): ?array
|
||||
{
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $qb
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid AS file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$qb->expr()->eq('fr.tablenames', $qb->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.fieldname', $qb->createNamedParameter('file', ParameterType::STRING)),
|
||||
$qb->expr()->eq('fr.uid_foreign', $qb->createNamedParameter($downloadUid, ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('fr.deleted', 0),
|
||||
$qb->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render a single market as JSON for headless output.
|
||||
*
|
||||
* `render()` = page discovery (top-level plugin). `renderForRecord()` =
|
||||
* one specific tt_content row, reused by ContainerChildrenProcessor and
|
||||
* ContentElementResolver. Exception-safe.
|
||||
*/
|
||||
class MarketShowJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_marketshow') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_marketshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$marketUid = (int)($settings['market'] ?? 0);
|
||||
$layout = (string)($settings['layout'] ?? 'default');
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// Fallback: route / query parameter (numeric uid only — Market has no slug)
|
||||
if (!$marketUid) {
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$marketParam = $routeParams['tx_vitec_marketshow']['market'] ?? null;
|
||||
if ($marketParam && is_numeric($marketParam)) {
|
||||
$marketUid = (int)$marketParam;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$marketUid) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No market selected or found', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$marketQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_market');
|
||||
|
||||
$market = $marketQb
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_market')
|
||||
->where(
|
||||
$marketQb->expr()->eq('uid', $marketQb->createNamedParameter($marketUid, ParameterType::INTEGER)),
|
||||
$marketQb->expr()->eq('deleted', 0),
|
||||
$marketQb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$market) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Market not found', 'debug' => ['marketUid' => $marketUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'market' => $this->serializeMarket($market),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'marketUid' => $marketUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $market
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeMarket(array $market): array
|
||||
{
|
||||
$uid = (int)$market['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($market['title'] ?? ''),
|
||||
'subtitle' => (string)($market['subtitle'] ?? ''),
|
||||
'teaser' => (string)($market['teaser'] ?? ''),
|
||||
'description' => (string)($market['description'] ?? ''),
|
||||
'categories' => $this->getMarketCategories($uid),
|
||||
'image' => $this->getMarketImage($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the single image FAL reference for a market (fieldname=image).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getMarketImage(int $marketUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_market', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('image', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($marketUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$variant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($variant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$default = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($default),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMarketCategories(int $marketUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_market', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($marketUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
}
|
||||
Executable → Regular
+26
-3
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@@ -25,9 +27,30 @@ use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_productlist') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
@@ -37,7 +60,7 @@ class ProductListJsonRenderer
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
@@ -45,13 +68,13 @@ class ProductListJsonRenderer
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
// Not a product-list page: emit nothing so headless removes the key.
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-list plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render product list as JSON for headless
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
// IMPORTANT: Headless creates new cObj contexts when rendering JSON fields,
|
||||
// losing the current content element context. Also, Extbase repositories don't work
|
||||
// in UserFunc context because the full Extbase framework isn't bootstrapped.
|
||||
//
|
||||
// Solution: Query tt_content directly to find the plugin configuration,
|
||||
// then use direct database queries for products instead of Extbase repositories.
|
||||
|
||||
// Get current page UID
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
// Query tt_content for vitec_productlist on this page
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return json_encode(['debug' => 'No vitec_productlist on page ' . $pageId]);
|
||||
}
|
||||
|
||||
// Take the first one (there should typically be only one)
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
// Extract category UIDs and debug setting
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
$allProducts = (bool)($settings['allproducts'] ?? false);
|
||||
|
||||
// Extbase repositories don't work in UserFunc context
|
||||
// Use direct database query instead
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productQuery = $productQueryBuilder
|
||||
->select('p.*')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('p.deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hidden', 0),
|
||||
$productQueryBuilder->expr()->eq('p.legacy', 0),
|
||||
$productQueryBuilder->expr()->eq('p.supportproduct', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonwebsite', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonproducts', 0),
|
||||
$productQueryBuilder->expr()->eq('p.subproduct', 0)
|
||||
);
|
||||
|
||||
// Add category filter if specified and allProducts is not enabled
|
||||
if (!empty($categoryUids) && !$allProducts) {
|
||||
// Join with sys_category_record_mm to filter by categories
|
||||
$productQuery
|
||||
->join(
|
||||
'p',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid AND mm.tablenames = ' . $productQueryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) . ' AND mm.fieldname = ' . $productQueryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->andWhere(
|
||||
$productQueryBuilder->expr()->in('mm.uid_local', $productQueryBuilder->createNamedParameter($categoryUids, Connection::PARAM_INT_ARRAY))
|
||||
)
|
||||
->groupBy('p.uid');
|
||||
}
|
||||
|
||||
$products = $productQuery->executeQuery()->fetchAllAssociative();
|
||||
|
||||
// Serialize products (they're already associative arrays from the query)
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
// Get product images (FAL references)
|
||||
$images = $this->getProductImages((int)$product['uid']);
|
||||
|
||||
$productsData[] = [
|
||||
'uid' => (int)$product['uid'],
|
||||
'title' => $product['title'] ?? '',
|
||||
'subtitle' => $product['subtitle'] ?? '',
|
||||
'slug' => $product['slug'] ?? '',
|
||||
'teaser' => $product['teaser'] ?? '',
|
||||
'description' => $product['description'] ?? '',
|
||||
'link' => '/product/' . ($product['slug'] ?? ''),
|
||||
'images' => $images,
|
||||
// Add more fields as needed
|
||||
];
|
||||
}
|
||||
|
||||
// If debug mode is enabled, return object with products and debug info
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
'debug' => [
|
||||
'pageId' => $pageId,
|
||||
'categoryUids' => $categoryUids,
|
||||
'productCount' => count($productsData),
|
||||
'settings' => $settings
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Otherwise return products array directly (backward compatible)
|
||||
return json_encode($productsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product images from FAL (sys_file_reference)
|
||||
* Processes images through ImageService and generates srcset for responsive images
|
||||
*/
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.uid_local', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
|
||||
$images = [];
|
||||
foreach ($fileReferences as $fileRefData) {
|
||||
try {
|
||||
// Get FAL FileReference object
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
// Define image sizes for srcset
|
||||
$sizes = [
|
||||
'small' => ['width' => 400, 'height' => null],
|
||||
'medium' => ['width' => 800, 'height' => null],
|
||||
'large' => ['width' => 1200, 'height' => null],
|
||||
'xlarge' => ['width' => 1600, 'height' => null],
|
||||
];
|
||||
|
||||
$srcset = [];
|
||||
foreach ($sizes as $sizeName => $dimensions) {
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
[
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
'crop' => $fileRefData['crop'] ?? null
|
||||
]
|
||||
);
|
||||
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
$srcset[] = [
|
||||
'url' => $imageUri,
|
||||
'width' => $dimensions['width'],
|
||||
'descriptor' => $dimensions['width'] . 'w'
|
||||
];
|
||||
}
|
||||
|
||||
// Get original/default image
|
||||
$defaultProcessed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
$images[] = [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($defaultProcessed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type')
|
||||
]
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// Skip images that can't be processed
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
}
|
||||
@@ -1,499 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render product list as JSON for headless
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
// IMPORTANT: Headless creates new cObj contexts when rendering JSON fields,
|
||||
// losing the current content element context. Also, Extbase repositories don't work
|
||||
// in UserFunc context because the full Extbase framework isn't bootstrapped.
|
||||
//
|
||||
// Solution: Query tt_content directly to find the plugin configuration,
|
||||
// then use direct database queries for products instead of Extbase repositories.
|
||||
|
||||
// Get current page UID
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
// Query tt_content for vitec_productlist on this page
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return json_encode(['debug' => 'No vitec_productlist on page ' . $pageId]);
|
||||
}
|
||||
|
||||
// Take the first one (there should typically be only one)
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
// Extract category UIDs and debug setting
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
$allProducts = (bool)($settings['allproducts'] ?? false);
|
||||
|
||||
// Extbase repositories don't work in UserFunc context
|
||||
// Use direct database query instead
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productQuery = $productQueryBuilder
|
||||
->select('p.*')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('p.deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hidden', 0),
|
||||
$productQueryBuilder->expr()->eq('p.legacy', 0),
|
||||
$productQueryBuilder->expr()->eq('p.supportproduct', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonwebsite', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonproducts', 0),
|
||||
$productQueryBuilder->expr()->eq('p.subproduct', 0)
|
||||
);
|
||||
|
||||
// Add category filter if specified and allProducts is not enabled
|
||||
if (!empty($categoryUids) && !$allProducts) {
|
||||
// Join with sys_category_record_mm to filter by categories
|
||||
$productQuery
|
||||
->join(
|
||||
'p',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid AND mm.tablenames = ' . $productQueryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) . ' AND mm.fieldname = ' . $productQueryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->andWhere(
|
||||
$productQueryBuilder->expr()->in('mm.uid_local', $productQueryBuilder->createNamedParameter($categoryUids, Connection::PARAM_INT_ARRAY))
|
||||
)
|
||||
->groupBy('p.uid');
|
||||
}
|
||||
|
||||
$products = $productQuery->executeQuery()->fetchAllAssociative();
|
||||
|
||||
// Serialize products (they're already associative arrays from the query)
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
$productsData[] = $this->serializeProduct($product);
|
||||
}
|
||||
|
||||
// If debug mode is enabled, return object with products and debug info
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
'debug' => [
|
||||
'pageId' => $pageId,
|
||||
'categoryUids' => $categoryUids,
|
||||
'productCount' => count($productsData),
|
||||
'settings' => $settings
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Otherwise return products array directly (backward compatible)
|
||||
return json_encode($productsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single product DB row to the full headless JSON structure.
|
||||
*
|
||||
* Includes every field declared on the Product domain model
|
||||
* (Evomedien\Vitec\Domain\Model\Product) plus all fully resolved
|
||||
* relations (categories, productimage, downloads, ogimage, relatedprodukt).
|
||||
*
|
||||
* DB-only columns that are NOT part of the domain model
|
||||
* (cta, links, sorting1-5, key1-3, apptext1-3, productlayout, image,
|
||||
* relatedimage, system fields) are intentionally omitted.
|
||||
*
|
||||
* @param array<string,mixed> $product Associative DB row of tx_vitec_domain_model_product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
// --- identifier ---
|
||||
'uid' => $uid,
|
||||
|
||||
// --- scalar string fields (Product domain model) ---
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
// --- boolean flags (Product domain model) ---
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
// --- convenience link (kept for backward compatibility) ---
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
// --- fully resolved relations ---
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product images from FAL (sys_file_reference)
|
||||
* Processes images through ImageService and generates srcset for responsive images
|
||||
*/
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.uid_local', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
|
||||
$images = [];
|
||||
foreach ($fileReferences as $fileRefData) {
|
||||
try {
|
||||
// Get FAL FileReference object
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
// Define image sizes for srcset
|
||||
$sizes = [
|
||||
'small' => ['width' => 400, 'height' => null],
|
||||
'medium' => ['width' => 800, 'height' => null],
|
||||
'large' => ['width' => 1200, 'height' => null],
|
||||
'xlarge' => ['width' => 1600, 'height' => null],
|
||||
];
|
||||
|
||||
$srcset = [];
|
||||
foreach ($sizes as $sizeName => $dimensions) {
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
[
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
'crop' => $fileRefData['crop'] ?? null
|
||||
]
|
||||
);
|
||||
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
$srcset[] = [
|
||||
'url' => $imageUri,
|
||||
'width' => $dimensions['width'],
|
||||
'descriptor' => $dimensions['width'] . 'w'
|
||||
];
|
||||
}
|
||||
|
||||
// Get original/default image
|
||||
$defaultProcessed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
$images[] = [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($defaultProcessed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type')
|
||||
]
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// Skip images that can't be processed
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the single Open Graph image (ogimage) for a product, or null.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$processed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($processed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a product (resolved sys_category records).
|
||||
*/
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all downloads for a product (resolved via tx_vitec_product_download_mm).
|
||||
*/
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
// Get file information from FAL if file reference exists
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related products (resolved via tx_vitec_product_related_mm).
|
||||
*
|
||||
* Returns a shallow representation (no nested relations) to avoid
|
||||
* infinite recursion between mutually related products.
|
||||
*/
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$images = $this->getProductImages($relUid);
|
||||
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $images,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,463 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render product list as JSON for headless.
|
||||
*
|
||||
* `render()` performs page discovery (used for top-level list plugins via
|
||||
* TypoScript). `renderForRecord()` processes one specific tt_content row and
|
||||
* is used both internally and by ContainerChildrenProcessor to resolve a
|
||||
* product-list plugin nested inside a b13 container.
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
// Not a product-list page: emit nothing so headless removes the key.
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-list plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement tt_content row of the plugin
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
// Parse FlexForm of THIS element
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
$allProducts = (bool)($settings['allproducts'] ?? false);
|
||||
|
||||
// Extbase repositories don't work in UserFunc context — direct query.
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productQuery = $productQueryBuilder
|
||||
->select('p.*')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('p.deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hidden', 0),
|
||||
$productQueryBuilder->expr()->eq('p.legacy', 0),
|
||||
$productQueryBuilder->expr()->eq('p.supportproduct', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonwebsite', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonproducts', 0),
|
||||
$productQueryBuilder->expr()->eq('p.subproduct', 0)
|
||||
);
|
||||
|
||||
if (!empty($categoryUids) && !$allProducts) {
|
||||
$productQuery
|
||||
->join(
|
||||
'p',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid AND mm.tablenames = ' . $productQueryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) . ' AND mm.fieldname = ' . $productQueryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->andWhere(
|
||||
$productQueryBuilder->expr()->in('mm.uid_local', $productQueryBuilder->createNamedParameter($categoryUids, Connection::PARAM_INT_ARRAY))
|
||||
)
|
||||
->groupBy('p.uid');
|
||||
}
|
||||
|
||||
$products = $productQuery->executeQuery()->fetchAllAssociative();
|
||||
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
$productsData[] = $this->serializeProduct($product);
|
||||
}
|
||||
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
'debug' => [
|
||||
'pageId' => (int)($GLOBALS['TSFE']->id ?? 0),
|
||||
'categoryUids' => $categoryUids,
|
||||
'productCount' => count($productsData),
|
||||
'settings' => $settings,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode($productsData);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single product DB row to the full headless JSON structure.
|
||||
*
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.uid_local', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
|
||||
$images = [];
|
||||
foreach ($fileReferences as $fileRefData) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$sizes = [
|
||||
'small' => ['width' => 400, 'height' => null],
|
||||
'medium' => ['width' => 800, 'height' => null],
|
||||
'large' => ['width' => 1200, 'height' => null],
|
||||
'xlarge' => ['width' => 1600, 'height' => null],
|
||||
];
|
||||
|
||||
$srcset = [];
|
||||
foreach ($sizes as $sizeName => $dimensions) {
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
[
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
'crop' => $fileRefData['crop'] ?? null
|
||||
]
|
||||
);
|
||||
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
$srcset[] = [
|
||||
'url' => $imageUri,
|
||||
'width' => $dimensions['width'],
|
||||
'descriptor' => $dimensions['width'] . 'w'
|
||||
];
|
||||
}
|
||||
|
||||
$defaultProcessed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
$images[] = [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($defaultProcessed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type')
|
||||
]
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$processed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($processed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,507 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render product list as JSON for headless.
|
||||
*
|
||||
* `render()` performs page discovery (used for top-level list plugins via
|
||||
* TypoScript). `renderForRecord()` processes one specific tt_content row and
|
||||
* is used both internally and by ContainerChildrenProcessor to resolve a
|
||||
* product-list plugin nested inside a b13 container.
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
// Not a product-list page: emit nothing so headless removes the key.
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-list plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement tt_content row of the plugin
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
// Parse FlexForm of THIS element
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
$allProducts = (bool)($settings['allproducts'] ?? false);
|
||||
|
||||
// Extbase repositories don't work in UserFunc context — direct query.
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productQuery = $productQueryBuilder
|
||||
->select('p.*')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('p.deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hidden', 0),
|
||||
$productQueryBuilder->expr()->eq('p.legacy', 0),
|
||||
$productQueryBuilder->expr()->eq('p.supportproduct', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonwebsite', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonproducts', 0),
|
||||
$productQueryBuilder->expr()->eq('p.subproduct', 0)
|
||||
);
|
||||
|
||||
if (!empty($categoryUids) && !$allProducts) {
|
||||
$productQuery
|
||||
->join(
|
||||
'p',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid AND mm.tablenames = ' . $productQueryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) . ' AND mm.fieldname = ' . $productQueryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->andWhere(
|
||||
$productQueryBuilder->expr()->in('mm.uid_local', $productQueryBuilder->createNamedParameter($categoryUids, Connection::PARAM_INT_ARRAY))
|
||||
)
|
||||
->groupBy('p.uid');
|
||||
}
|
||||
|
||||
$products = $productQuery->executeQuery()->fetchAllAssociative();
|
||||
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
$productsData[] = $this->serializeProduct($product);
|
||||
}
|
||||
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
'debug' => [
|
||||
'pageId' => (int)($GLOBALS['TSFE']->id ?? 0),
|
||||
'categoryUids' => $categoryUids,
|
||||
'productCount' => count($productsData),
|
||||
'settings' => $settings,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode($productsData);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single product DB row to the full headless JSON structure.
|
||||
*
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'videofile' => $this->getProductVideoFile($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.uid_local', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
|
||||
$images = [];
|
||||
foreach ($fileReferences as $fileRefData) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$sizes = [
|
||||
'small' => ['width' => 400, 'height' => null],
|
||||
'medium' => ['width' => 800, 'height' => null],
|
||||
'large' => ['width' => 1200, 'height' => null],
|
||||
'xlarge' => ['width' => 1600, 'height' => null],
|
||||
];
|
||||
|
||||
$srcset = [];
|
||||
foreach ($sizes as $sizeName => $dimensions) {
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
[
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
'crop' => $fileRefData['crop'] ?? null
|
||||
]
|
||||
);
|
||||
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
$srcset[] = [
|
||||
'url' => $imageUri,
|
||||
'width' => $dimensions['width'],
|
||||
'descriptor' => $dimensions['width'] . 'w'
|
||||
];
|
||||
}
|
||||
|
||||
$defaultProcessed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
$images[] = [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($defaultProcessed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type')
|
||||
]
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$processed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($processed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the uploaded video file (single FAL reference, fieldname=videofile).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductVideoFile(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $queryBuilder
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('fr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.fieldname', $queryBuilder->createNamedParameter('videofile', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.uid_foreign', $queryBuilder->createNamedParameter($productUid, \Doctrine\DBAL\ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('fr.hidden', 0),
|
||||
$queryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,507 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render product list as JSON for headless.
|
||||
*
|
||||
* `render()` performs page discovery (used for top-level list plugins via
|
||||
* TypoScript). `renderForRecord()` processes one specific tt_content row and
|
||||
* is used both internally and by ContainerChildrenProcessor to resolve a
|
||||
* product-list plugin nested inside a b13 container.
|
||||
*/
|
||||
class ProductListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productlist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
// Not a product-list page: emit nothing so headless removes the key.
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-list plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement tt_content row of the plugin
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
// Parse FlexForm of THIS element
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
$allProducts = (bool)($settings['allproducts'] ?? false);
|
||||
|
||||
// Extbase repositories don't work in UserFunc context — direct query.
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productQuery = $productQueryBuilder
|
||||
->select('p.*')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('p.deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hidden', 0),
|
||||
$productQueryBuilder->expr()->eq('p.legacy', 0),
|
||||
$productQueryBuilder->expr()->eq('p.supportproduct', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonwebsite', 0),
|
||||
$productQueryBuilder->expr()->eq('p.hideonproducts', 0),
|
||||
$productQueryBuilder->expr()->eq('p.subproduct', 0)
|
||||
);
|
||||
|
||||
if (!empty($categoryUids) && !$allProducts) {
|
||||
$productQuery
|
||||
->join(
|
||||
'p',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid AND mm.tablenames = ' . $productQueryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) . ' AND mm.fieldname = ' . $productQueryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->andWhere(
|
||||
$productQueryBuilder->expr()->in('mm.uid_local', $productQueryBuilder->createNamedParameter($categoryUids, Connection::PARAM_INT_ARRAY))
|
||||
)
|
||||
->groupBy('p.uid');
|
||||
}
|
||||
|
||||
$products = $productQuery->executeQuery()->fetchAllAssociative();
|
||||
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
$productsData[] = $this->serializeProduct($product);
|
||||
}
|
||||
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
'debug' => [
|
||||
'pageId' => (int)($GLOBALS['TSFE']->id ?? 0),
|
||||
'categoryUids' => $categoryUids,
|
||||
'productCount' => count($productsData),
|
||||
'settings' => $settings,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode($productsData);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single product DB row to the full headless JSON structure.
|
||||
*
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => \Evomedien\Vitec\Service\ContentElementResolver::resolveLink((string)($product['contentelement'] ?? '')),
|
||||
'contentelementcta' => \Evomedien\Vitec\Service\ContentElementResolver::resolveLink((string)($product['contentelementcta'] ?? '')),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'videofile' => $this->getProductVideoFile($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.uid_local', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
|
||||
$images = [];
|
||||
foreach ($fileReferences as $fileRefData) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$sizes = [
|
||||
'small' => ['width' => 400, 'height' => null],
|
||||
'medium' => ['width' => 800, 'height' => null],
|
||||
'large' => ['width' => 1200, 'height' => null],
|
||||
'xlarge' => ['width' => 1600, 'height' => null],
|
||||
];
|
||||
|
||||
$srcset = [];
|
||||
foreach ($sizes as $sizeName => $dimensions) {
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
[
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
'crop' => $fileRefData['crop'] ?? null
|
||||
]
|
||||
);
|
||||
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
$srcset[] = [
|
||||
'url' => $imageUri,
|
||||
'width' => $dimensions['width'],
|
||||
'descriptor' => $dimensions['width'] . 'w'
|
||||
];
|
||||
}
|
||||
|
||||
$defaultProcessed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
$images[] = [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($defaultProcessed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type')
|
||||
]
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$processed = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($processed),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the uploaded video file (single FAL reference, fieldname=videofile).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductVideoFile(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $queryBuilder
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('fr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.fieldname', $queryBuilder->createNamedParameter('videofile', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.uid_foreign', $queryBuilder->createNamedParameter($productUid, \Doctrine\DBAL\ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('fr.hidden', 0),
|
||||
$queryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+27
-3
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -23,11 +25,32 @@ use Doctrine\DBAL\ParameterType;
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_productshow') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
@@ -35,7 +58,7 @@ class ProductShowJsonRenderer
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
@@ -49,6 +72,7 @@ class ProductShowJsonRenderer
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-show plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
|
||||
@@ -1,366 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Imaging\ImageService;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
/**
|
||||
* UserFunc to render single product data as JSON for headless output
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)$GLOBALS['TSFE']->id;
|
||||
|
||||
// DEBUG: Log that the UserFunc is being called
|
||||
$debugInfo = [
|
||||
'userFuncCalled' => true,
|
||||
'pageId' => $pageId,
|
||||
'requestUri' => $_SERVER['REQUEST_URI'] ?? 'unknown',
|
||||
];
|
||||
|
||||
// Query tt_content for vitec_productshow on this page
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$debugInfo['contentElementsFound'] = count($contentElements);
|
||||
|
||||
if (empty($contentElements)) {
|
||||
$debugInfo['error'] = 'No vitec_productshow on page';
|
||||
return json_encode(['debug' => $debugInfo]);
|
||||
}
|
||||
|
||||
// Take the first one
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
// Get product UID from FlexForm or route parameter
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$layout = (int)($settings['layout'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// If no product selected in FlexForm, try to get from route parameter
|
||||
if (!$productUid) {
|
||||
// Get the product parameter from GET request
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$productParam = $routeParams['tx_vitec_productshow']['product'] ?? null;
|
||||
|
||||
if ($productParam) {
|
||||
// If it's a slug, resolve it to UID
|
||||
if (!is_numeric($productParam)) {
|
||||
$slugQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productBySlug = $slugQueryBuilder
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$slugQueryBuilder->expr()->eq('slug', $slugQueryBuilder->createNamedParameter($productParam)),
|
||||
$slugQueryBuilder->expr()->eq('deleted', 0),
|
||||
$slugQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
$productUid = (int)($productBySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$productUid = (int)$productParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$productUid) {
|
||||
return json_encode([
|
||||
'error' => 'No product selected or found',
|
||||
'debug' => [
|
||||
'settings' => $settings,
|
||||
'routeParams' => $routeParams ?? [],
|
||||
'allQueryParams' => $GLOBALS['TYPO3_REQUEST']->getQueryParams() ?? [],
|
||||
'requestUri' => $GLOBALS['TYPO3_REQUEST']->getUri()->getPath() ?? ''
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Query product
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$product = $productQueryBuilder
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('uid', $productQueryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$productQueryBuilder->expr()->eq('deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$product) {
|
||||
return json_encode([
|
||||
'error' => 'Product not found',
|
||||
'debug' => $debugMode ? ['productUid' => $productUid] : null
|
||||
]);
|
||||
}
|
||||
|
||||
// Get product images
|
||||
$images = $this->getProductImages((int)$product['uid']);
|
||||
|
||||
// Get categories
|
||||
$categories = $this->getProductCategories((int)$product['uid']);
|
||||
|
||||
// Get downloads
|
||||
$downloads = $this->getProductDownloads((int)$product['uid']);
|
||||
|
||||
// Build response
|
||||
$response = [
|
||||
'product' => [
|
||||
'uid' => (int)$product['uid'],
|
||||
'title' => $product['title'],
|
||||
'subtitle' => $product['subtitle'],
|
||||
'slug' => $product['slug'],
|
||||
'teaser' => $product['teaser'],
|
||||
'description' => $product['description'],
|
||||
'seotitle' => $product['seotitle'],
|
||||
'categories' => $categories,
|
||||
'images' => $images,
|
||||
'downloads' => $downloads,
|
||||
],
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all images for a product with FAL and ImageService processing
|
||||
*/
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($fileReferences)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$images = [];
|
||||
|
||||
foreach ($fileReferences as $fileRef) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
// Process main image
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => '1874c', 'height' => '625c']
|
||||
);
|
||||
|
||||
// Generate srcset
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width . 'c', 'height' => (int)($width / 3) . 'c']
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// Skip invalid file references
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a product
|
||||
*/
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'],
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all downloads for a product
|
||||
*/
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
// Get file information from FAL if file reference exists
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,512 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Imaging\ImageService;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
/**
|
||||
* UserFunc to render single product data as JSON for headless output
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)$GLOBALS['TSFE']->id;
|
||||
|
||||
// DEBUG: Log that the UserFunc is being called
|
||||
$debugInfo = [
|
||||
'userFuncCalled' => true,
|
||||
'pageId' => $pageId,
|
||||
'requestUri' => $_SERVER['REQUEST_URI'] ?? 'unknown',
|
||||
];
|
||||
|
||||
// Query tt_content for vitec_productshow on this page
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$debugInfo['contentElementsFound'] = count($contentElements);
|
||||
|
||||
if (empty($contentElements)) {
|
||||
$debugInfo['error'] = 'No vitec_productshow on page';
|
||||
return json_encode(['debug' => $debugInfo]);
|
||||
}
|
||||
|
||||
// Take the first one
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
// Get product UID from FlexForm or route parameter
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$layout = (int)($settings['layout'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// If no product selected in FlexForm, try to get from route parameter
|
||||
if (!$productUid) {
|
||||
// Get the product parameter from GET request
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$productParam = $routeParams['tx_vitec_productshow']['product'] ?? null;
|
||||
|
||||
if ($productParam) {
|
||||
// If it's a slug, resolve it to UID
|
||||
if (!is_numeric($productParam)) {
|
||||
$slugQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productBySlug = $slugQueryBuilder
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$slugQueryBuilder->expr()->eq('slug', $slugQueryBuilder->createNamedParameter($productParam)),
|
||||
$slugQueryBuilder->expr()->eq('deleted', 0),
|
||||
$slugQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
$productUid = (int)($productBySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$productUid = (int)$productParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$productUid) {
|
||||
return json_encode([
|
||||
'error' => 'No product selected or found',
|
||||
'debug' => [
|
||||
'settings' => $settings,
|
||||
'routeParams' => $routeParams ?? [],
|
||||
'allQueryParams' => $GLOBALS['TYPO3_REQUEST']->getQueryParams() ?? [],
|
||||
'requestUri' => $GLOBALS['TYPO3_REQUEST']->getUri()->getPath() ?? ''
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Query product
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$product = $productQueryBuilder
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('uid', $productQueryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$productQueryBuilder->expr()->eq('deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$product) {
|
||||
return json_encode([
|
||||
'error' => 'Product not found',
|
||||
'debug' => $debugMode ? ['productUid' => $productUid] : null
|
||||
]);
|
||||
}
|
||||
|
||||
// Build response (full Product domain model + resolved relations)
|
||||
$response = [
|
||||
'product' => $this->serializeProduct($product),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single product DB row to the full headless JSON structure.
|
||||
*
|
||||
* Includes every field declared on the Product domain model
|
||||
* (Evomedien\Vitec\Domain\Model\Product) plus all fully resolved
|
||||
* relations (categories, productimage, downloads, ogimage, relatedprodukt).
|
||||
*
|
||||
* Kept structurally identical to ProductListJsonRenderer::serializeProduct()
|
||||
* so list and detail endpoints expose the same product schema.
|
||||
*
|
||||
* @param array<string,mixed> $product Associative DB row of tx_vitec_domain_model_product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
// --- identifier ---
|
||||
'uid' => $uid,
|
||||
|
||||
// --- scalar string fields (Product domain model) ---
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
// --- boolean flags (Product domain model) ---
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
// --- convenience link (kept for backward compatibility) ---
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
// --- fully resolved relations ---
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all images for a product with FAL and ImageService processing
|
||||
*/
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($fileReferences)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$images = [];
|
||||
|
||||
foreach ($fileReferences as $fileRef) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
// Process main image
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => '1874c', 'height' => '625c']
|
||||
);
|
||||
|
||||
// Generate srcset
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width . 'c', 'height' => (int)($width / 3) . 'c']
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// Skip invalid file references
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the single Open Graph image (ogimage) for a product, or null.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a product
|
||||
*/
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'],
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all downloads for a product
|
||||
*/
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
// Get file information from FAL if file reference exists
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related products (resolved via tx_vitec_product_related_mm).
|
||||
*
|
||||
* Returns a shallow representation (no nested relations) to avoid
|
||||
* infinite recursion between mutually related products.
|
||||
*/
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,470 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Imaging\ImageService;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
/**
|
||||
* UserFunc to render a single product as JSON for headless output.
|
||||
*
|
||||
* `render()` performs page discovery (top-level plugin via TypoScript).
|
||||
* `renderForRecord()` processes one specific tt_content row and is reused
|
||||
* by ContainerChildrenProcessor for product-show plugins nested in a
|
||||
* b13 container.
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-show plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$layout = (int)($settings['layout'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
if (!$productUid) {
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$productParam = $routeParams['tx_vitec_productshow']['product'] ?? null;
|
||||
|
||||
if ($productParam) {
|
||||
if (!is_numeric($productParam)) {
|
||||
$slugQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productBySlug = $slugQueryBuilder
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$slugQueryBuilder->expr()->eq('slug', $slugQueryBuilder->createNamedParameter($productParam)),
|
||||
$slugQueryBuilder->expr()->eq('deleted', 0),
|
||||
$slugQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
$productUid = (int)($productBySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$productUid = (int)$productParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$productUid) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No product selected or found', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$product = $productQueryBuilder
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('uid', $productQueryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$productQueryBuilder->expr()->eq('deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$product) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Product not found', 'debug' => ['productUid' => $productUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'product' => $this->serializeProduct($product),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($fileReferences)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$images = [];
|
||||
|
||||
foreach ($fileReferences as $fileRef) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => '1874c', 'height' => '625c']
|
||||
);
|
||||
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width . 'c', 'height' => (int)($width / 3) . 'c']
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'],
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,514 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Imaging\ImageService;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
/**
|
||||
* UserFunc to render a single product as JSON for headless output.
|
||||
*
|
||||
* `render()` performs page discovery (top-level plugin via TypoScript).
|
||||
* `renderForRecord()` processes one specific tt_content row and is reused
|
||||
* by ContainerChildrenProcessor for product-show plugins nested in a
|
||||
* b13 container.
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-show plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$layout = (int)($settings['layout'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
if (!$productUid) {
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$productParam = $routeParams['tx_vitec_productshow']['product'] ?? null;
|
||||
|
||||
if ($productParam) {
|
||||
if (!is_numeric($productParam)) {
|
||||
$slugQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productBySlug = $slugQueryBuilder
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$slugQueryBuilder->expr()->eq('slug', $slugQueryBuilder->createNamedParameter($productParam)),
|
||||
$slugQueryBuilder->expr()->eq('deleted', 0),
|
||||
$slugQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
$productUid = (int)($productBySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$productUid = (int)$productParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$productUid) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No product selected or found', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$product = $productQueryBuilder
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('uid', $productQueryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$productQueryBuilder->expr()->eq('deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$product) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Product not found', 'debug' => ['productUid' => $productUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'product' => $this->serializeProduct($product),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => (string)($product['contentelement'] ?? ''),
|
||||
'contentelementcta' => (string)($product['contentelementcta'] ?? ''),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'videofile' => $this->getProductVideoFile($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($fileReferences)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$images = [];
|
||||
|
||||
foreach ($fileReferences as $fileRef) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => '1874c', 'height' => '625c']
|
||||
);
|
||||
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width . 'c', 'height' => (int)($width / 3) . 'c']
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the uploaded video file (single FAL reference, fieldname=videofile).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductVideoFile(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $queryBuilder
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('fr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.fieldname', $queryBuilder->createNamedParameter('videofile', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.uid_foreign', $queryBuilder->createNamedParameter($productUid, \Doctrine\DBAL\ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('fr.hidden', 0),
|
||||
$queryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'],
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,514 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Imaging\ImageService;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
/**
|
||||
* UserFunc to render a single product as JSON for headless output.
|
||||
*
|
||||
* `render()` performs page discovery (top-level plugin via TypoScript).
|
||||
* `renderForRecord()` processes one specific tt_content row and is reused
|
||||
* by ContainerChildrenProcessor for product-show plugins nested in a
|
||||
* b13 container.
|
||||
*/
|
||||
class ProductShowJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter('vitec_productshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render exactly the given tt_content row (the product-show plugin element).
|
||||
* Exception-safe: returns '' on any failure.
|
||||
*
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$productUid = (int)($settings['product'] ?? 0);
|
||||
$layout = (int)($settings['layout'] ?? 0);
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
if (!$productUid) {
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$productParam = $routeParams['tx_vitec_productshow']['product'] ?? null;
|
||||
|
||||
if ($productParam) {
|
||||
if (!is_numeric($productParam)) {
|
||||
$slugQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$productBySlug = $slugQueryBuilder
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$slugQueryBuilder->expr()->eq('slug', $slugQueryBuilder->createNamedParameter($productParam)),
|
||||
$slugQueryBuilder->expr()->eq('deleted', 0),
|
||||
$slugQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
$productUid = (int)($productBySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$productUid = (int)$productParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$productUid) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No product selected or found', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$productQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$product = $productQueryBuilder
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_product')
|
||||
->where(
|
||||
$productQueryBuilder->expr()->eq('uid', $productQueryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$productQueryBuilder->expr()->eq('deleted', 0),
|
||||
$productQueryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$product) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Product not found', 'debug' => ['productUid' => $productUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'product' => $this->serializeProduct($product),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'productUid' => $productUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $product
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeProduct(array $product): array
|
||||
{
|
||||
$uid = (int)$product['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
|
||||
'title' => (string)($product['title'] ?? ''),
|
||||
'slug' => (string)($product['slug'] ?? ''),
|
||||
'urltitle' => (string)($product['urltitle'] ?? ''),
|
||||
'seotitle' => (string)($product['seotitle'] ?? ''),
|
||||
'seometa' => (string)($product['seometa'] ?? ''),
|
||||
'keywords' => (string)($product['keywords'] ?? ''),
|
||||
'structureddata' => (string)($product['structureddata'] ?? ''),
|
||||
'teaser' => (string)($product['teaser'] ?? ''),
|
||||
'subtitle' => (string)($product['subtitle'] ?? ''),
|
||||
'video' => (string)($product['video'] ?? ''),
|
||||
'applications' => (string)($product['applications'] ?? ''),
|
||||
'description' => (string)($product['description'] ?? ''),
|
||||
'highlights' => (string)($product['highlights'] ?? ''),
|
||||
'shortcutpid' => (string)($product['shortcutpid'] ?? ''),
|
||||
'contentelement' => \Evomedien\Vitec\Service\ContentElementResolver::resolveLink((string)($product['contentelement'] ?? '')),
|
||||
'contentelementcta' => \Evomedien\Vitec\Service\ContentElementResolver::resolveLink((string)($product['contentelementcta'] ?? '')),
|
||||
|
||||
'hideonapp' => (bool)($product['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($product['hideonwebsite'] ?? false),
|
||||
'hideondatasheets' => (bool)($product['hideondatasheets'] ?? false),
|
||||
'hideonproducts' => (bool)($product['hideonproducts'] ?? false),
|
||||
'shortcut' => (bool)($product['shortcut'] ?? false),
|
||||
'legacy' => (bool)($product['legacy'] ?? false),
|
||||
'supportproduct' => (bool)($product['supportproduct'] ?? false),
|
||||
'subproduct' => (bool)($product['subproduct'] ?? false),
|
||||
|
||||
'link' => '/product/' . (string)($product['slug'] ?? ''),
|
||||
|
||||
'categories' => $this->getProductCategories($uid),
|
||||
'images' => $this->getProductImages($uid),
|
||||
'downloads' => $this->getProductDownloads($uid),
|
||||
'ogimage' => $this->getProductOgImage($uid),
|
||||
'videofile' => $this->getProductVideoFile($uid),
|
||||
'relatedprodukt' => $this->getRelatedProducts($uid),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getProductImages(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileReferences = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('productimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($fileReferences)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$images = [];
|
||||
|
||||
foreach ($fileReferences as $fileRef) {
|
||||
try {
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => '1874c', 'height' => '625c']
|
||||
);
|
||||
|
||||
$srcset = [];
|
||||
foreach ([400, 800, 1200, 1600] as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width . 'c', 'height' => (int)($width / 3) . 'c']
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductOgImage(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $queryBuilder
|
||||
->select('*')
|
||||
->from('sys_file_reference')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('ogimage', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->orderBy('sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject($fileRef['uid']);
|
||||
$originalFile = $fileReference->getOriginalFile();
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 1200]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => $fileRef['uid'],
|
||||
'url' => $imageService->getImageUri($processedImage),
|
||||
'title' => $fileReference->getTitle() ?: '',
|
||||
'alternative' => $fileReference->getAlternative() ?: '',
|
||||
'description' => $fileReference->getDescription() ?: '',
|
||||
'properties' => [
|
||||
'width' => $originalFile->getProperty('width'),
|
||||
'height' => $originalFile->getProperty('height'),
|
||||
'mimeType' => $originalFile->getMimeType(),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the uploaded video file (single FAL reference, fieldname=videofile).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getProductVideoFile(int $productUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$row = $queryBuilder
|
||||
->select('fr.uid', 'fr.title', 'fr.description', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('fr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_product', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.fieldname', $queryBuilder->createNamedParameter('videofile', \Doctrine\DBAL\ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('fr.uid_foreign', $queryBuilder->createNamedParameter($productUid, \Doctrine\DBAL\ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('fr.hidden', 0),
|
||||
$queryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'uid' => (int)$row['file_uid'],
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'url' => '/fileadmin' . ($row['identifier'] ?? ''),
|
||||
'size' => (int)($row['size'] ?? 0),
|
||||
'extension' => (string)($row['extension'] ?? ''),
|
||||
'mimeType' => (string)($row['mime_type'] ?? ''),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'description' => (string)($row['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
protected function getProductCategories(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_product', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'],
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
protected function getProductDownloads(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_download');
|
||||
|
||||
$downloads = $queryBuilder
|
||||
->select('d.*')
|
||||
->from('tx_vitec_domain_model_download', 'd')
|
||||
->join(
|
||||
'd',
|
||||
'tx_vitec_product_download_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = d.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('d.deleted', 0),
|
||||
$queryBuilder->expr()->eq('d.hidden', 0),
|
||||
$queryBuilder->expr()->eq('d.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($downloads as $download) {
|
||||
$fileInfo = null;
|
||||
|
||||
if (!empty($download['file'])) {
|
||||
$fileQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRef = $fileQueryBuilder
|
||||
->select('fr.uid', 'f.uid as file_uid', 'f.identifier', 'f.name', 'f.size', 'f.extension', 'f.mime_type')
|
||||
->from('sys_file_reference', 'fr')
|
||||
->join('fr', 'sys_file', 'f', 'fr.uid_local = f.uid')
|
||||
->where(
|
||||
$fileQueryBuilder->expr()->eq('fr.uid_foreign', $fileQueryBuilder->createNamedParameter((int)$download['uid'], ParameterType::INTEGER)),
|
||||
$fileQueryBuilder->expr()->eq('fr.tablenames', $fileQueryBuilder->createNamedParameter('tx_vitec_domain_model_download', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.fieldname', $fileQueryBuilder->createNamedParameter('file', ParameterType::STRING)),
|
||||
$fileQueryBuilder->expr()->eq('fr.deleted', 0),
|
||||
$fileQueryBuilder->expr()->eq('f.missing', 0)
|
||||
)
|
||||
->orderBy('fr.sorting_foreign', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if ($fileRef) {
|
||||
$fileInfo = [
|
||||
'uid' => (int)$fileRef['file_uid'],
|
||||
'name' => $fileRef['name'],
|
||||
'url' => '/fileadmin' . $fileRef['identifier'],
|
||||
'size' => (int)$fileRef['size'],
|
||||
'extension' => $fileRef['extension'],
|
||||
'mimeType' => $fileRef['mime_type'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'uid' => (int)$download['uid'],
|
||||
'title' => $download['title'] ?? '',
|
||||
'slug' => $download['slug'] ?? '',
|
||||
'teaser' => $download['teaser'] ?? '',
|
||||
'description' => $download['description'] ?? '',
|
||||
'keywords' => $download['keywords'] ?? '',
|
||||
'icon' => $download['icon'] ?? '',
|
||||
'file' => $fileInfo,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRelatedProducts(int $productUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_product');
|
||||
|
||||
$related = $queryBuilder
|
||||
->select('p.uid', 'p.title', 'p.slug', 'p.subtitle', 'p.teaser', 'p.description')
|
||||
->from('tx_vitec_domain_model_product', 'p')
|
||||
->join(
|
||||
'p',
|
||||
'tx_vitec_product_related_mm',
|
||||
'mm',
|
||||
'mm.uid_foreign = p.uid'
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($productUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('p.deleted', 0),
|
||||
$queryBuilder->expr()->eq('p.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$result = [];
|
||||
foreach ($related as $rel) {
|
||||
$relUid = (int)$rel['uid'];
|
||||
$result[] = [
|
||||
'uid' => $relUid,
|
||||
'title' => (string)($rel['title'] ?? ''),
|
||||
'slug' => (string)($rel['slug'] ?? ''),
|
||||
'subtitle' => (string)($rel['subtitle'] ?? ''),
|
||||
'teaser' => (string)($rel['teaser'] ?? ''),
|
||||
'description' => (string)($rel['description'] ?? ''),
|
||||
'link' => '/product/' . (string)($rel['slug'] ?? ''),
|
||||
'images' => $this->getProductImages($relUid),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+94
-95
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
@@ -12,106 +14,115 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render a single usecase as JSON for headless output.
|
||||
* UserFunc to render a single solution as JSON for headless output.
|
||||
*
|
||||
* Mirrors ProductShowJsonRenderer. Extbase repositories are unavailable in a
|
||||
* UserFunc context, so tt_content and the usecase record are queried directly.
|
||||
* Exception-safe: returns '' on any failure / when not applicable so headless
|
||||
* `ifEmptyUnsetKey` drops the key entirely.
|
||||
* `render()` = page discovery (top-level plugin). `renderForRecord()` =
|
||||
* one specific tt_content row, reused by ContainerChildrenProcessor and
|
||||
* ContentElementResolver. Exception-safe.
|
||||
*/
|
||||
class UsecaseShowJsonRenderer
|
||||
class SolutionShowJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_solutionshow') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_solutionshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
// Find the vitec_usecaseshow plugin on this page
|
||||
$ttContentQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $ttContentQb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$ttContentQb->expr()->eq('pid', $ttContentQb->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$ttContentQb->expr()->eq('list_type', $ttContentQb->createNamedParameter('vitec_usecaseshow', ParameterType::STRING)),
|
||||
$ttContentQb->expr()->eq('deleted', 0),
|
||||
$ttContentQb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
$usecaseUid = (int)($settings['usecase'] ?? 0);
|
||||
$solutionUid = (int)($settings['solution'] ?? 0);
|
||||
$layout = (string)($settings['layout'] ?? 'default');
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// Fall back to route / query parameter (uid or slug)
|
||||
if (!$usecaseUid) {
|
||||
// Fallback: route / query parameter (numeric uid only — Market has no slug)
|
||||
if (!$solutionUid) {
|
||||
$routeParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
|
||||
$usecaseParam = $routeParams['tx_vitec_usecaseshow']['usecase'] ?? null;
|
||||
|
||||
if ($usecaseParam) {
|
||||
if (!is_numeric($usecaseParam)) {
|
||||
$slugQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_usecase');
|
||||
$bySlug = $slugQb
|
||||
->select('uid')
|
||||
->from('tx_vitec_domain_model_usecase')
|
||||
->where(
|
||||
$slugQb->expr()->eq('slug', $slugQb->createNamedParameter($usecaseParam)),
|
||||
$slugQb->expr()->eq('deleted', 0),
|
||||
$slugQb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
$usecaseUid = (int)($bySlug['uid'] ?? 0);
|
||||
} else {
|
||||
$usecaseUid = (int)$usecaseParam;
|
||||
}
|
||||
$solutionParam = $routeParams['tx_vitec_solutionshow']['solution'] ?? null;
|
||||
if ($solutionParam && is_numeric($solutionParam)) {
|
||||
$solutionUid = (int)$solutionParam;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$usecaseUid) {
|
||||
if (!$solutionUid) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'No usecase selected or found', 'debug' => ['settings' => $settings]])
|
||||
? json_encode(['error' => 'No solution selected or found', 'debug' => ['settings' => $settings]])
|
||||
: '';
|
||||
}
|
||||
|
||||
// Query the usecase
|
||||
$usecaseQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_usecase');
|
||||
$solutionQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_solution');
|
||||
|
||||
$usecase = $usecaseQb
|
||||
$solution = $solutionQb
|
||||
->select('*')
|
||||
->from('tx_vitec_domain_model_usecase')
|
||||
->from('tx_vitec_domain_model_solution')
|
||||
->where(
|
||||
$usecaseQb->expr()->eq('uid', $usecaseQb->createNamedParameter($usecaseUid, ParameterType::INTEGER)),
|
||||
$usecaseQb->expr()->eq('deleted', 0),
|
||||
$usecaseQb->expr()->eq('hidden', 0)
|
||||
$solutionQb->expr()->eq('uid', $solutionQb->createNamedParameter($solutionUid, ParameterType::INTEGER)),
|
||||
$solutionQb->expr()->eq('deleted', 0),
|
||||
$solutionQb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$usecase) {
|
||||
if (!$solution) {
|
||||
return $debugMode
|
||||
? json_encode(['error' => 'Usecase not found', 'debug' => ['usecaseUid' => $usecaseUid]])
|
||||
? json_encode(['error' => 'Solution not found', 'debug' => ['solutionUid' => $solutionUid]])
|
||||
: '';
|
||||
}
|
||||
|
||||
$response = [
|
||||
'usecase' => $this->serializeUsecase($usecase),
|
||||
'solution' => $this->serializeSolution($solution),
|
||||
'layout' => $layout,
|
||||
'settings' => [
|
||||
'layout' => $layout,
|
||||
@@ -121,7 +132,7 @@ class UsecaseShowJsonRenderer
|
||||
if ($debugMode) {
|
||||
$response['debug'] = [
|
||||
'pageId' => $pageId,
|
||||
'usecaseUid' => $usecaseUid,
|
||||
'solutionUid' => $solutionUid,
|
||||
'layout' => $layout,
|
||||
'settings' => $settings,
|
||||
];
|
||||
@@ -134,39 +145,30 @@ class UsecaseShowJsonRenderer
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single usecase DB row. Structurally identical to
|
||||
* UsecaseListJsonRenderer::serializeUsecase() so list and detail
|
||||
* endpoints expose the same usecase schema.
|
||||
*
|
||||
* @param array<string,mixed> $usecase
|
||||
* @param array<string,mixed> $solution
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeUsecase(array $usecase): array
|
||||
protected function serializeSolution(array $solution): array
|
||||
{
|
||||
$uid = (int)$usecase['uid'];
|
||||
$uid = (int)$solution['uid'];
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($usecase['title'] ?? ''),
|
||||
'slug' => (string)($usecase['slug'] ?? ''),
|
||||
'subtitle' => (string)($usecase['subtitle'] ?? ''),
|
||||
'teaser' => (string)($usecase['teaser'] ?? ''),
|
||||
'description' => (string)($usecase['description'] ?? ''),
|
||||
'singlepid' => (string)($usecase['singlepid'] ?? ''),
|
||||
'hideonapp' => (bool)($usecase['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($usecase['hideonwebsite'] ?? false),
|
||||
'categories' => $this->getUsecaseCategories($uid),
|
||||
'caseimage' => $this->getUsecaseImage($uid, 'caseimage'),
|
||||
'logoimage' => $this->getUsecaseImage($uid, 'logoimage'),
|
||||
'title' => (string)($solution['title'] ?? ''),
|
||||
'subtitle' => (string)($solution['subtitle'] ?? ''),
|
||||
'teaser' => (string)($solution['teaser'] ?? ''),
|
||||
'description' => (string)($solution['description'] ?? ''),
|
||||
'categories' => $this->getSolutionCategories($uid),
|
||||
'image' => $this->getSolutionImage($uid),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a single FAL image field (caseimage / logoimage) with srcset.
|
||||
* Resolve the single image FAL reference for a market (fieldname=image).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getUsecaseImage(int $usecaseUid, string $fieldName): ?array
|
||||
protected function getSolutionImage(int $solutionUid): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
@@ -175,9 +177,9 @@ class UsecaseShowJsonRenderer
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_usecase', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter($fieldName, ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($usecaseUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_solution', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter('image', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($solutionUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
@@ -231,10 +233,7 @@ class UsecaseShowJsonRenderer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a usecase (resolved sys_category records).
|
||||
*/
|
||||
protected function getUsecaseCategories(int $usecaseUid): array
|
||||
protected function getSolutionCategories(int $solutionUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
@@ -247,12 +246,12 @@ class UsecaseShowJsonRenderer
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_usecase', ParameterType::STRING) .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_solution', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($usecaseUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($solutionUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
Executable → Regular
+31
-7
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
@@ -20,21 +22,42 @@ use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
*/
|
||||
class UsecaseListJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_usecaselist') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
$ttContentQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $ttContentQb
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$ttContentQb->expr()->eq('pid', $ttContentQb->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$ttContentQb->expr()->eq('list_type', $ttContentQb->createNamedParameter('vitec_usecaselist', ParameterType::STRING)),
|
||||
$ttContentQb->expr()->eq('deleted', 0),
|
||||
$ttContentQb->expr()->eq('hidden', 0)
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_usecaselist', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
@@ -46,6 +69,7 @@ class UsecaseListJsonRenderer
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* UserFunc to render the usecase list as JSON for headless output.
|
||||
*
|
||||
* Mirrors ProductListJsonRenderer: Extbase repositories don't work in a
|
||||
* UserFunc context (framework not bootstrapped), so tt_content and the
|
||||
* usecase records are queried directly. Exception-safe: returns an empty
|
||||
* string on any failure so headless `ifEmptyUnsetKey` can drop the key.
|
||||
*/
|
||||
class UsecaseListJsonRenderer
|
||||
{
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
try {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
|
||||
// Find the vitec_usecaselist plugin on this page
|
||||
$ttContentQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $ttContentQb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$ttContentQb->expr()->eq('pid', $ttContentQb->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$ttContentQb->expr()->eq('list_type', $ttContentQb->createNamedParameter('vitec_usecaselist', ParameterType::STRING)),
|
||||
$ttContentQb->expr()->eq('deleted', 0),
|
||||
$ttContentQb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($contentElements)) {
|
||||
// Not a usecase-list page (or none configured): emit nothing
|
||||
// so headless removes the key entirely.
|
||||
return '';
|
||||
}
|
||||
|
||||
$contentElement = $contentElements[0];
|
||||
|
||||
// Parse FlexForm (debug flag only; the list shows all visible usecases)
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
// Query visible usecases directly (Extbase unavailable in UserFunc)
|
||||
$usecaseQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_vitec_domain_model_usecase');
|
||||
|
||||
$usecases = $usecaseQb
|
||||
->select('u.*')
|
||||
->from('tx_vitec_domain_model_usecase', 'u')
|
||||
->where(
|
||||
$usecaseQb->expr()->eq('u.deleted', 0),
|
||||
$usecaseQb->expr()->eq('u.hidden', 0),
|
||||
$usecaseQb->expr()->eq('u.hideonwebsite', 0)
|
||||
)
|
||||
->orderBy('u.title', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
$usecasesData = [];
|
||||
foreach ($usecases as $usecase) {
|
||||
$usecasesData[] = $this->serializeUsecase($usecase);
|
||||
}
|
||||
|
||||
if ($debugMode) {
|
||||
return json_encode([
|
||||
'usecases' => $usecasesData,
|
||||
'debug' => [
|
||||
'pageId' => $pageId,
|
||||
'usecaseCount' => count($usecasesData),
|
||||
'settings' => $settings,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode($usecasesData);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single usecase DB row to the full headless JSON structure.
|
||||
*
|
||||
* Includes every field declared on the Usecase domain model
|
||||
* (Evomedien\Vitec\Domain\Model\Usecase) plus all resolved relations
|
||||
* (categories, caseimage, logoimage). Kept structurally analogous to
|
||||
* ProductListJsonRenderer::serializeProduct().
|
||||
*
|
||||
* @param array<string,mixed> $usecase
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
protected function serializeUsecase(array $usecase): array
|
||||
{
|
||||
$uid = (int)$usecase['uid'];
|
||||
|
||||
return [
|
||||
// --- identifier ---
|
||||
'uid' => $uid,
|
||||
|
||||
// --- scalar string fields (Usecase domain model) ---
|
||||
'title' => (string)($usecase['title'] ?? ''),
|
||||
'slug' => (string)($usecase['slug'] ?? ''),
|
||||
'subtitle' => (string)($usecase['subtitle'] ?? ''),
|
||||
'teaser' => (string)($usecase['teaser'] ?? ''),
|
||||
'description' => (string)($usecase['description'] ?? ''),
|
||||
'singlepid' => (string)($usecase['singlepid'] ?? ''),
|
||||
|
||||
// --- boolean flags (Usecase domain model) ---
|
||||
'hideonapp' => (bool)($usecase['hideonapp'] ?? false),
|
||||
'hideonwebsite' => (bool)($usecase['hideonwebsite'] ?? false),
|
||||
|
||||
// --- fully resolved relations ---
|
||||
'categories' => $this->getUsecaseCategories($uid),
|
||||
'caseimage' => $this->getUsecaseImage($uid, 'caseimage'),
|
||||
'logoimage' => $this->getUsecaseImage($uid, 'logoimage'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a single FAL image field (caseimage / logoimage) with srcset.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
protected function getUsecaseImage(int $usecaseUid, string $fieldName): ?array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_file_reference');
|
||||
|
||||
$fileRefData = $queryBuilder
|
||||
->select('sfr.uid', 'sfr.title', 'sfr.description', 'sfr.alternative', 'sfr.crop')
|
||||
->from('sys_file_reference', 'sfr')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('sfr.tablenames', $queryBuilder->createNamedParameter('tx_vitec_domain_model_usecase', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.fieldname', $queryBuilder->createNamedParameter($fieldName, ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('sfr.uid_foreign', $queryBuilder->createNamedParameter($usecaseUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('sfr.deleted', 0),
|
||||
$queryBuilder->expr()->eq('sfr.hidden', 0)
|
||||
)
|
||||
->orderBy('sfr.sorting_foreign')
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
if (!$fileRefData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$fileReference = $resourceFactory->getFileReferenceObject((int)$fileRefData['uid']);
|
||||
|
||||
$sizes = [400, 800, 1200, 1600];
|
||||
$srcset = [];
|
||||
foreach ($sizes as $width) {
|
||||
$processedVariant = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => $width, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
$srcset[] = [
|
||||
'url' => $imageService->getImageUri($processedVariant),
|
||||
'width' => $width,
|
||||
'descriptor' => $width . 'w',
|
||||
];
|
||||
}
|
||||
|
||||
$default = $imageService->applyProcessingInstructions(
|
||||
$fileReference,
|
||||
['width' => 800, 'crop' => $fileRefData['crop'] ?? null]
|
||||
);
|
||||
|
||||
return [
|
||||
'uid' => (int)$fileRefData['uid'],
|
||||
'url' => $imageService->getImageUri($default),
|
||||
'title' => $fileRefData['title'] ?? '',
|
||||
'alternative' => $fileRefData['alternative'] ?? '',
|
||||
'description' => $fileRefData['description'] ?? '',
|
||||
'srcset' => $srcset,
|
||||
'properties' => [
|
||||
'width' => $fileReference->getProperty('width'),
|
||||
'height' => $fileReference->getProperty('height'),
|
||||
'mimeType' => $fileReference->getProperty('mime_type'),
|
||||
],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a usecase (resolved sys_category records).
|
||||
*/
|
||||
protected function getUsecaseCategories(int $usecaseUid): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('sys_category');
|
||||
|
||||
$categories = $queryBuilder
|
||||
->select('c.uid', 'c.title', 'c.description')
|
||||
->from('sys_category', 'c')
|
||||
->join(
|
||||
'c',
|
||||
'sys_category_record_mm',
|
||||
'mm',
|
||||
'mm.uid_local = c.uid AND mm.tablenames = ' .
|
||||
$queryBuilder->createNamedParameter('tx_vitec_domain_model_usecase', ParameterType::STRING) .
|
||||
' AND mm.fieldname = ' .
|
||||
$queryBuilder->createNamedParameter('categories', ParameterType::STRING)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('mm.uid_foreign', $queryBuilder->createNamedParameter($usecaseUid, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('c.deleted', 0),
|
||||
$queryBuilder->expr()->eq('c.hidden', 0)
|
||||
)
|
||||
->orderBy('mm.sorting', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
return array_map(static function ($cat) {
|
||||
return [
|
||||
'uid' => (int)$cat['uid'],
|
||||
'title' => $cat['title'] ?? '',
|
||||
'description' => $cat['description'] ?? '',
|
||||
];
|
||||
}, $categories);
|
||||
}
|
||||
}
|
||||
Executable → Regular
+31
-7
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
@@ -20,21 +22,42 @@ use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
*/
|
||||
class UsecaseShowJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
// 1) cObj data path
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && (string)($row['CType'] ?? '') === 'vitec_usecaseshow') {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
$ttContentQb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
// 2) Page-id via v14 request attribute (TSFE->id is often null in JSON cObj context)
|
||||
$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 '';
|
||||
}
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
|
||||
$contentElements = $ttContentQb
|
||||
$contentElements = $queryBuilder
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$ttContentQb->expr()->eq('pid', $ttContentQb->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$ttContentQb->expr()->eq('list_type', $ttContentQb->createNamedParameter('vitec_usecaseshow', ParameterType::STRING)),
|
||||
$ttContentQb->expr()->eq('deleted', 0),
|
||||
$ttContentQb->expr()->eq('hidden', 0)
|
||||
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('vitec_usecaseshow', ParameterType::STRING)),
|
||||
$queryBuilder->expr()->eq('deleted', 0),
|
||||
$queryBuilder->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
@@ -46,6 +69,7 @@ class UsecaseShowJsonRenderer
|
||||
return $this->renderForRecord($contentElements[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
|
||||
Executable → Regular
+5
@@ -62,6 +62,11 @@ final class BackendLayoutDataProvider implements DataProviderInterface
|
||||
'preFooter' => 'Pre-Footer',
|
||||
];
|
||||
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'vitec';
|
||||
}
|
||||
|
||||
public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
|
||||
{
|
||||
foreach (self::LAYOUT_MAP as $value => $info) {
|
||||
|
||||
Executable → Regular
+1
-1
@@ -10,7 +10,7 @@ use TYPO3\CMS\Backend\View\BackendLayoutView;
|
||||
* Overrides BackendLayoutView so the page module always reflects pages.layout
|
||||
* without the editor having to set backend_layout manually.
|
||||
*/
|
||||
final class VitecBackendLayoutView extends BackendLayoutView
|
||||
final readonly class VitecBackendLayoutView extends BackendLayoutView
|
||||
{
|
||||
public function getSelectedCombinedIdentifier(int $pageId): string|false
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user