Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty $result['databaseRow']['colPos'] array gets interpreted as 0 #92

Open
kosimas opened this issue Nov 17, 2021 · 8 comments
Open

Empty $result['databaseRow']['colPos'] array gets interpreted as 0 #92

kosimas opened this issue Nov 17, 2021 · 8 comments

Comments

@kosimas
Copy link

kosimas commented Nov 17, 2021

$colPos = (int)($result['databaseRow']['colPos'][0] ?? ($result['databaseRow']['colPos'] ?? 0));

This line causes issues with new IRRE inline elements that have for example a non existing colPos of 999.
If a inline child element is created, it will load all allowed CType values for colPos 0.

Before setting $colPos to 0, it should be checked if $result["processedTca"]["columns"]["colPos"]["config"]["default"] exists and if so,
$colPos should get the value.

A solution could look like this(this is probably doable with less code)

if (gettype($result['databaseRow']['colPos']) == 'array')
    $hasColPos = array_key_exists(0, $result['databaseRow']['colPos']);
else if (gettype($result['databaseRow']['colPos']) == 'int')
    $hasColPos = true;
else
    $hasColPos = false;

if (!$hasColPos) {
    $processedTcaTypeColPos = $result["processedTca"]["columns"]["colPos"]["config"]["default"] ?? false;
}

if (gettype($processedTcaTypeColPos) == 'string')
    $colPos = (int)$processedTcaTypeColPos;
else if (gettype($processedTcaTypeColPos) == 'integer')
    $colPos = $processedTcaTypeColPos;
else
    $colPos = (int)($result['databaseRow']['colPos'][0] ?? ($result['databaseRow']['colPos'] ?? 0));

Edit:
Steps to reproduce
This problem can be reproduced by creating an TCA inline element like this:

$GLOBALS['TCA']['tt_content']['columns']['text_tab_text_elements'] = [
    'config' => [
        'appearance' => [
            'collapseAll' => '1',
            'enabledControls' => [
                'dragdrop' => '1',
            ],
            'levelLinksPosition' => 'top',
            'showAllLocalizationLink' => '1',
            'showPossibleLocalizationRecords' => '1',
            'showSynchronizationLink' => '1',
            'useSortable' => '1',
        ],
        'foreign_sortby' => 'sorting',
        'foreign_table' => 'tt_content',
        'overrideChildTca' => [
            'columns' => [
                'colPos' => [
                    'config' => [
                        'default' => '999',
                    ],
                ],
                'CType' => [
                    'config' => [
                        'default' => 'text',
                    ],
                ],
            ],
        ],
        'type' => 'inline',
        'foreign_field' => 'text_tab_text_elements_parent',
    ],
    'exclude' => '1',
    'label' => 'LLL:EXT:sitepackage/Resources/Private/Language/Backend.xlf:text_tab_text_elements.label',
];

Then create a content element that is using this element.
After that try to add this content element to a page that has text elements disallowed on colPos 0.
Now creating child text elements inside the inline element is not working properly.

Typo3: ^10.4, ^11.5
Content Defender: ^3.2

@IchHabRecht
Copy link
Owner

Hi @kosimas,

Would you mind to share your actual problem and how to reproduce it. I can't copy&paste any code to solve a problem I cannot reproduce. Thank you very much.

@kosimas
Copy link
Author

kosimas commented Nov 17, 2021

Hey @IchHabRecht,
thanks for the quick reply. I edited the issue. Let me know if you need more information.

@IchHabRecht
Copy link
Owner

Hi @kosimas,

I tried to reproduce the problem, but was unable to do so. For an IRRE child element the correct colPos configured in overrideChildTca -> columns -> colPos -> config -> default is taken into account. if this colPos isn't configured in the backendLayout configuration there shouldn't be any overlapping. Are you using any other extension that handles colPos configuration on it's own and maybe has strange site effects with content_defender?

@kosimas
Copy link
Author

kosimas commented Dec 18, 2021

Hey @IchHabRecht,
I created a sitepackage extension for reproducing this bug.
https://github.com/kosimas/content_defender_bug_sitepackage

I have added some information and instructions to the readme file
https://github.com/kosimas/content_defender_bug_sitepackage/blob/master/README.md

I hope this will help to understand the problem.
Let me know if something is still unclear ☺️

@kosimas
Copy link
Author

kosimas commented May 9, 2022

#75
This can be considered as related.

@liayn
Copy link

liayn commented Sep 20, 2022

This also happens if you have "unused content elements". E.g. when upgrading a website and using new backend layouts, with different colPos numbers.
Trying to edit such a content element yields an empty colPos array in the databaseRow.

@liayn
Copy link

liayn commented Sep 20, 2022

$isCurrentColPos = $colPos === (int)($result['databaseRow']['colPos'][0] ?? 0); is sufficient for us to fix it

@liayn
Copy link

liayn commented Oct 10, 2022

see #109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants