Files
VITEC-website/packages/vitec/Classes/Preview/UsecaseshowPluginPreview.php
T
orasche 78af83d2e3 - The three market Content Blocks preview as compact collapsible rows:
thumbnail of the actual image (hero background, intro image, insights
  cover), key copy in the summary line, full details expanded; card and
  intro-paragraph previews are wrapped in the same mechanism
- New SubmarketPluginPreview for vitec_usecaselist / vitec_productfeature /
  vitec_productlist: instead of bare standard boxes they now list the
  selected story titles (flagging stories that still lack a quote), the
  featured product and the hand-picked products in order
- Container-style collapse for whole page-module COLUMNS: a chevron at the
  right of every column header folds a section down to its title row,
  state kept per page and colPos in localStorage - the slot view of a
  sub-market page folds to six slim bands
- Previews sit under the page module's pointer-events lock and its
  click-to-edit layer: pointer events are re-enabled inside the collapse
  markup and the toggle runs on pointerdown in the capture phase
- Two more v14 removals fixed on the way, both latent in the OLDER preview
  classes too (Usecaseshow, Modelcard would have crashed the page module):
  GridColumnItem::getRecord() now returns a Domain\Record object, and
  StandaloneView is gone - previews normalize the record via a shared
  helper and render through the ViewFactory
2026-10-02 15:00:05 +02:00

106 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Evomedien\Vitec\Preview;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Evomedien\Vitec\Domain\Repository\UsecaseRepository;
/**
* Preview class for the Usecaseshow plugin
*/
class UsecaseshowPluginPreview extends StandardContentPreviewRenderer
{
/**
* @param GridColumnItem $item
* @return string
*/
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$record = $this->recordArray($item);
// v14: StandaloneView was removed - views come from the ViewFactory.
$view = GeneralUtility::makeInstance(\TYPO3\CMS\Core\View\ViewFactoryInterface::class)
->create(new \TYPO3\CMS\Core\View\ViewFactoryData(
templatePathAndFilename: 'EXT:vitec/Resources/Private/Templates/Preview/Usecaseshow.html',
request: $GLOBALS['TYPO3_REQUEST'] ?? null,
));
// Parse FlexForm data
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
$flexFormData = $flexFormService->convertFlexFormContentToArray($record['pi_flexform'] ?? '');
// Get usecase data if selected
$usecaseData = null;
$usecaseUid = (int)($flexFormData['settings']['usecase'] ?? 0);
if ($usecaseUid > 0) {
$usecaseRepository = GeneralUtility::makeInstance(UsecaseRepository::class);
$usecase = $usecaseRepository->findByUid($usecaseUid);
if ($usecase) {
$usecaseData = [
'uid' => $usecase->getUid(),
'title' => $usecase->getTitle(),
'subtitle' => $usecase->getSubtitle(),
'description' => $usecase->getDescription()
];
}
}
// Get layout setting
$layout = $flexFormData['settings']['layout'] ?? 'default';
// Assign variables to view
$view->assignMultiple([
'record' => $record,
'flexFormData' => $flexFormData,
'usecase' => $usecaseData,
'layout' => $layout,
'pluginName' => 'Usecaseshow'
]);
return $view->render();
}
/**
* @param GridColumnItem $item
* @return string
*/
public function renderPageModulePreviewHeader(GridColumnItem $item): string
{
$record = $this->recordArray($item);
// Parse FlexForm to get usecase info for header
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
$flexFormData = $flexFormService->convertFlexFormContentToArray($record['pi_flexform'] ?? '');
$usecaseUid = (int)($flexFormData['settings']['usecase'] ?? 0);
if ($usecaseUid > 0) {
return '<strong>🎯 Usecase Show Plugin</strong> <small>(Usecase ID: ' . $usecaseUid . ')</small>';
}
return '<strong>🎯 Usecase Show Plugin</strong> <small style="color: orange;">(No usecase selected)</small>';
}
/**
* v14: GridColumnItem::getRecord() returns a Domain\Record object, no
* longer an array (found 2026-10-02 - crashed the page module preview).
* Normalizes both shapes to the raw database array.
*
* @return array<string,mixed>
*/
private function recordArray(GridColumnItem $item): array
{
$record = $item->getRecord();
if ($record instanceof \TYPO3\CMS\Core\Domain\Record) {
$raw = $record->getRawRecord();
return $raw !== null ? $raw->toArray() : [];
}
return (array)$record;
}
}