getRecord()->getRawRecord() ?? $item->getRecord(); $request = $item->getContext()->getCurrentRequest(); if (!$this->tcaSchemaFactory->has($record->getFullType())) { return ''; } $schema = $this->tcaSchemaFactory->get($item->getTable()); $outHeader = ''; if ($record->has('header_layout')) { $headerLayout = (string)$record->get('header_layout'); if ($headerLayout === '100') { $headerLayoutHiddenLabel = $this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:header_layout.I.6'); $outHeader .= '
' . htmlspecialchars($headerLayoutHiddenLabel) . '
'; } } $dateLabel = $this->fieldProcessor->prepareFieldWithLabel($record, 'date'); if ($dateLabel) { $outHeader .= '
' . htmlspecialchars(strip_tags($dateLabel)) . '
'; } if ($schema->hasCapability(TcaSchemaCapability::Label)) { $labelFieldName = $schema->getCapability(TcaSchemaCapability::Label)->getPrimaryFieldName(); $label = $this->fieldProcessor->prepareText($record, $labelFieldName); if ($label !== null) { $outHeader .= '
' . $this->fieldProcessor->linkToEditForm($label, $record, $request) . '
'; } } $subHeader = $this->fieldProcessor->prepareText($record, 'subheader'); if ($subHeader !== null) { $outHeader .= '
' . $this->fieldProcessor->linkToEditForm($subHeader, $record, $request) . '
'; } return $outHeader; } public function renderPageModulePreviewContent(GridColumnItem $item): string { $recordObj = $item->getRecord(); // This preview should only be used for tt_content records. if ($recordObj->getMainType() !== 'tt_content') { return ''; } $languageService = $this->getLanguageService(); $recordType = $recordObj->getRecordType(); $schema = $this->tcaSchemaFactory->get($recordObj->getMainType()); // If the record type is unknown, render a warning message. if (!$schema->hasSubSchema($recordType)) { $message = sprintf( $languageService->sL('core.core:labels.noMatchingValue'), $recordType ); return '' . htmlspecialchars($message) . ''; } if (!$this->backendLayoutView->isCTypeAllowedInColPosByPage( $item->getRecordType(), $item->getColumn()->getColumnNumber() ?? 0, $item->getRecord()->getPid() )) { $message = sprintf( $languageService->sL('core.core:labels.typeNotAllowedInColumn'), $recordType ); return '' . htmlspecialchars($message) . ''; } $subSchema = $schema->getSubSchema($recordType); $request = $item->getContext()->getCurrentRequest(); // Draw preview of the item depending on its record type switch ($recordType) { case 'header': break; case 'shortcut': if ($recordObj->has('records') && ($records = $recordObj->get('records'))) { $shortcutContent = ''; $shortcutRecords = $records instanceof \Traversable ? $records : [$records]; foreach ($shortcutRecords as $shortcutRecord) { $shortcutTableName = $shortcutRecord->getMainType(); $row = $shortcutRecord->getRawRecord()?->toArray() ?? []; if ($recordObj instanceof Record) { $shortcutRecord = $this->translateShortcutRecord($recordObj, $shortcutRecord, $shortcutTableName); } $icon = $this->iconFactory->getIconForRecord($shortcutTableName, $row, IconSize::SMALL)->render(); $icon = BackendUtility::wrapClickMenuOnIcon( $icon, $shortcutTableName, $shortcutRecord->getUid(), '1' ); $pathToContainingPage = BackendUtility::getRecordPath($row['pid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 0); $title = BackendUtility::getRecordTitle($shortcutTableName, $row); $itemContent = htmlspecialchars($title) . ' [' . $recordObj->getUid() . '] ' . htmlspecialchars($pathToContainingPage) . ''; $shortcutContent .= '
  • ' . $icon . ' ' . $this->fieldProcessor->linkToEditForm($itemContent, $shortcutRecord, $request) . '
  • '; } return $shortcutContent !== '' ? '' : ''; } break; case 'menu_abstract': case 'menu_categorized_content': case 'menu_categorized_pages': case 'menu_pages': case 'menu_recently_updated': case 'menu_related_pages': case 'menu_section': case 'menu_section_pages': case 'menu_sitemap': case 'menu_sitemap_pages': case 'menu_subpages': $row = $recordObj->getRawRecord()?->toArray() ?? []; if ($recordType !== 'menu_sitemap' && (($row['pages'] ?? false) || ($row['selected_categories'] ?? false))) { // Show pages/categories if the menu type is not "Sitemap" $content = $this->generateListForMenuContentTypes($row, $recordType); return $this->fieldProcessor->linkToEditForm($content, $recordObj, $request); } break; case 'bullets': $list = GeneralUtility::trimExplode(LF, $recordObj->get('bodytext') ?? '', true); if ($list !== []) { switch ($recordObj->get('bullets_type')) { case 0: $list = array_map( static fn(string $item) => '
  • ' . htmlspecialchars($item) . '
  • ', $list ); return ''; case 1: $list = array_map( static fn(string $item) => '
  • ' . htmlspecialchars($item) . '
  • ', $list ); return '
      ' . implode(LF, $list) . '
    '; case 2: $list = array_map( static fn(string $item): string => (static function () use ($item) { $split = GeneralUtility::trimExplode('|', $item, true, 2); return '
    ' . htmlspecialchars($split[0]) . '
    ' . '
    ' . htmlspecialchars($split[1] ?? '') . '
    '; })(), $list ); return '
    ' . implode(LF, $list) . '
    '; } } break; case 'html': $html = (string)$this->fieldProcessor->preparePlainHtml($recordObj, 'bodytext'); return $this->fieldProcessor->linkToEditForm($html, $recordObj, $request); default: $content = (string)$this->fieldProcessor->preparePreviewableHtml($recordObj, 'bodytext'); foreach ($subSchema->getFieldsOfType(TableColumnType::FILE) as $field) { $fieldName = $field->getName(); if ($recordObj->has($fieldName) && ($image = $recordObj->get($fieldName))) { $content .= $this->fieldProcessor->prepareFiles($image); } } return $this->fieldProcessor->linkToEditForm($content, $recordObj, $request); } return ''; } /** * Render a footer for the record */ public function renderPageModulePreviewFooter(GridColumnItem $item): string { $info = []; $record = $item->getRecord()->getRawRecord() ?? $item->getRecord(); $schema = $this->tcaSchemaFactory->get($item->getTable()); if ($schema->hasCapability(TcaSchemaCapability::RestrictionStartTime)) { $info[] = $this->fieldProcessor->prepareFieldWithLabel($record, $schema->getCapability(TcaSchemaCapability::RestrictionStartTime)->getFieldName()); } if ($schema->hasCapability(TcaSchemaCapability::RestrictionEndTime)) { $info[] = $this->fieldProcessor->prepareFieldWithLabel($record, $schema->getCapability(TcaSchemaCapability::RestrictionEndTime)->getFieldName()); } if ($schema->hasCapability(TcaSchemaCapability::RestrictionUserGroup)) { $info[] = $this->fieldProcessor->prepareFieldWithLabel($record, $schema->getCapability(TcaSchemaCapability::RestrictionUserGroup)->getFieldName()); } if ($record->getMainType() === 'tt_content') { foreach (['space_before_class', 'space_after_class'] as $additionalFieldName) { $itm = $this->fieldProcessor->prepareFieldWithLabel($record, $additionalFieldName); if ($itm !== null) { $info[] = $itm; } } } if ($schema->hasCapability(TcaSchemaCapability::InternalDescription)) { $item = $this->fieldProcessor->prepareField($record, $schema->getCapability(TcaSchemaCapability::InternalDescription)->getFieldName()); if ($item !== null) { $info[] = $item; } } $info = array_filter($info); if ($info === []) { return ''; } return implode('
    ', $info); } public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string { $previewHeader = $previewHeader ? '
    ' . $previewHeader . '
    ' : ''; $previewContent = $previewContent ? '
    ' . $previewContent . '
    ' : ''; return $previewHeader || $previewContent ? '
    ' . $previewHeader . $previewContent . '
    ' : ''; } private function translateShortcutRecord(Record $targetRecord, Record $shortcutRecord, string $tableName): RawRecord { $targetLanguage = ($targetRecord->getLanguageId() ?? 0); if ($targetLanguage === 0 || !$this->tcaSchemaFactory->get($tableName)->isLanguageAware() || $targetLanguage === ($shortcutRecord->getLanguageId() ?? 0) ) { return $shortcutRecord->getRawRecord(); } // record is localized - fetch the shortcut record translation, if available $shortcutRecordLocalization = $this->localizationRepository->getRecordTranslation($tableName, $shortcutRecord, $targetLanguage); return $shortcutRecordLocalization ?? $shortcutRecord->getRawRecord(); } /** * Generates a list of selected pages or categories for the menu content types * * @param array $record row from pages */ private function generateListForMenuContentTypes(array $record, string $contentType): string { $table = 'pages'; $field = 'pages'; // get categories instead of pages if (str_contains($contentType, 'menu_categorized')) { $table = 'sys_category'; $field = 'selected_categories'; } if (trim($record[$field] ?? '') === '') { return ''; } $content = ''; $uidList = GeneralUtility::intExplode(',', $record[$field], true); foreach ($uidList as $uid) { $pageRecord = BackendUtility::getRecord($table, $uid); if ($pageRecord) { $title = BackendUtility::getRecordTitle($table, $pageRecord); $pathToContainingPage = BackendUtility::getRecordPath($pageRecord['pid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 0); $content .= '
  • ' . htmlspecialchars($title) . ' [' . $uid . '] ' . htmlspecialchars($pathToContainingPage) . '
  • '; } } return $content ? '' : ''; } private function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }