Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Classes/Backend/Grid/ContainerGridColumnItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use B13\Container\Domain\Model\Container;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Core\Domain\RecordFactory;
Expand All @@ -21,7 +22,7 @@

class ContainerGridColumnItem extends GridColumnItem
{
public function __construct(PageLayoutContext $context, ContainerGridColumn $column, array $record, protected Container $container, protected ?string $newContentUrl)
public function __construct(PageLayoutContext $context, ContainerGridColumn $column, array $record, protected Registry $tcaRegistry, protected Container $container, protected ?string $newContentUrl)
{
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() > 13) {
$recordFactory = GeneralUtility::makeInstance(RecordFactory::class);
Expand All @@ -44,7 +45,10 @@ public function getWrapperClassName(): string
if ($this->isDisabled()) {
$wrapperClassNames[] = 't3-page-ce-hidden t3js-hidden-record';
}
// we do not need a "t3-page-ce-warning" class because we are build from Container
$record = $this->record;
if (!$this->tcaRegistry->recordIsAllowedInContainerColumn($record)) {
$wrapperClassNames[] = 't3-page-ce-warning';
}
return implode(' ', $wrapperClassNames);
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/Preview/GridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function renderGrid(array $record, PageLayoutContext $context): string
$records = $container->getChildrenByColPos($col['colPos']);
foreach ($records as $contentRecord) {
$url = $this->newContentUrlBuilder->getNewContentUrlAfterChild($context, $container, (int)$col['colPos'], (int)$contentRecord['uid'], $defVals);
$columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $container, $url);
$columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $this->tcaRegistry, $container, $url);
$columnObject->addItem($columnItem);
}
}
Expand Down
14 changes: 14 additions & 0 deletions Classes/Listener/PageContentPreviewRendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Domain\Record;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;

#[AsEventListener(identifier: 'tx-container-page-content-preview-rendering', before: 'typo3-backend/fluid-preview/content')]
class PageContentPreviewRendering
Expand All @@ -37,6 +38,14 @@ public function __invoke(PageContentPreviewRenderingEvent $event): void
}

$record = $event->getRecord();
if ($this->tcaRegistry->recordIsAllowedInContainerColumn($record) === false) {
$labels = $event->getPageLayoutContext()->getContentTypeLabels();
$label = $labels[$record->getRecordType()] ?? $record->getRecordType();
$label = sprintf($this->getLanguageService()->sL('core.core:labels.typeNotAllowedInColumn'), $label);
$content = '<span class="badge badge-warning">' . $label . '</span>';
$event->setPreviewContent($content);
return;
}
$recordType = $record->getRecordType();
if (!$this->tcaRegistry->isContainerElement($recordType)) {
return;
Expand All @@ -47,4 +56,9 @@ public function __invoke(PageContentPreviewRenderingEvent $event): void
$event->setRecord($recordWithRenderedGrid);
}
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
30 changes: 28 additions & 2 deletions Classes/Tca/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use B13\Container\Events\BeforeContainerConfigurationIsAppliedEvent;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Domain\RecordInterface;
use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
use TYPO3\CMS\Core\Imaging\IconRegistry;
Expand Down Expand Up @@ -108,10 +109,35 @@ public function getContentDefenderConfiguration(string $cType, int $colPos): arr
public function getAllowedCTypesInColumn(string $cType, int $colPos): ?array
{
$contentDefenderConfiguration = $this->getContentDefenderConfiguration($cType, $colPos);
if (empty($contentDefenderConfiguration['allowed.']['CType'])) {
if (empty($contentDefenderConfiguration['allowedContentTypes'])) {
return null;
}
return GeneralUtility::trimExplode(',', $contentDefenderConfiguration['allowed.']['CType'] ?? '', true);
return GeneralUtility::trimExplode(',', $contentDefenderConfiguration['allowedContentTypes'], true);
}

public function recordIsAllowedInContainerColumn(RecordInterface $record): bool
{
$recordType = $record->getRecordType();
if ($record->has('tx_container_parent')) {
$containerRecord = $record->get('tx_container_parent');
if ($containerRecord instanceof RecordInterface) {
$containerRecordType = $containerRecord->getRecordType();
if ($this->isContainerElement($containerRecordType)) {
return $this->isAllowedInColumn($recordType, (int)$record->get('colPos'), $containerRecordType);
}
}
}
return true;
}

public function isAllowedInColumn(string $cType, int $colPos, string $containerCType): bool
{
$contentDefenderConfiguration = $this->getContentDefenderConfiguration($cType, $colPos);
$disallowed = GeneralUtility::trimExplode(',', $contentDefenderConfiguration['disallowedContentTypes'] ?? '', true);
if (in_array($cType, $disallowed)) {
return false;
}
return in_array($cType, $this->getAllowedCTypesInColumn($containerCType, $colPos));
}

public function getAllAvailableColumnsColPos(string $cType): array
Expand Down
Loading