Skip to content

[bug] container ignores creationOptions if only 1 contentElementType is allowed #773

Description

@thomasrawiel

Summary

When a container allows only 1 specific content element type, its creationOptions are ignored when adding it to the container.
TYPO3 13: defaultValues, saveAndClose
TYPO3 14: additionally enableDirectRecordTypeCreation, title

creationOptions in TYPO3 docs

Example code

$GLOBALS['TCA']['tt_content']['types']['header']['creationOptions']['defaultValues'] = ['sectionIndex'=>0, 'header'=>'Example header', 'header_layout'=>5];

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\B13\Container\Tca\Registry::class)->configureContainer(
    (
    new \B13\Container\Tca\ContainerConfiguration(
        'b13-2cols-with-header-container', // CType
        '2 Column Container With Header', // label
        'Some Description of the Container', // description
        [
            [
                ['name' => 'header', 'colPos' => 200, 'colspan' => 2, 'allowed' => ['CType' => 'header']]
            ],
            [
                ['name' => 'left side', 'colPos' => 201],
                ['name' => 'right side', 'colPos' => 202]
            ]
        ] // grid configuration
    )
    )
        // set an optional icon configuration
        ->setIcon('EXT:container_example/Resources/Public/Icons/b13-2cols-with-header-container.svg')
);

Adds creation Options to the header CType.
Adds a container with a header column, where only the header CType is allowed.

Adding content to the header column selects the correct CType, but ignores the creationOptions/ defaultValues

Image

Cause

B13\Container\Backend\Preview\GridRenderer::getDefValsForContentDefenderAllowsOnlyOneSpecificContentType()

protected function getDefValsForContentDefenderAllowsOnlyOneSpecificContentType(string $cType, int $colPos): ?array
    {
        $allowedCTypes = (array)$this->tcaRegistry->getAllowedCTypesInColumn($cType, $colPos);
        if (count($allowedCTypes) === 1) {
            return ['CType' => $allowedCTypes[0]];
        }
        return null;
    }

The function only returns the CType to the defVal parameters.

Suggested Fix

Comparison with TYPO3 core backend-layout:

mod.web_layout.BackendLayouts {
    Subpage {
        title = Subpage
        config {
            backend_layout {
                colCount = 1
                rowCount = 2
                rows {
                    1 {
                        columns {
                            1 {
                                name = Header
                                colPos = 1
                                allowedContentTypes = header

                            }
                        }
                    }

                    2 {
                        columns {
                            1 {
                                name = Content
                                colPos = 0
                            }
                        }
                    }
                }
            }
        }
    }
}

When adding content to the header column, and in contrast to EXT:containr, the New Content Element Wizard is opened with the one allowed CType
Image

which results in the creation Options being applied:

Image

My suggestion is to remove the function to let TYPO3 handle the defaultValues/ creationOptions. This will have EXT:container use the same behaviour as TYPO3 core (display the New Content Element Wizard) when there is only one allowed content element type in the column.

I will add a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions