Bug #90925

Incorrectly selected items in MM select fields

Added by Sebastian Lechenbauer 8 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
-
Target version:
Start date:
2020-04-01
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

Description

After updating from TYPO3 9.5.14 to 9.5.15 there are incorrectly selected items in some of my backend select fields with MM relations.

I can reproduce this behaviour in 9.5.14 with a patch of change "2020-03-06 622e1a3dcd [BUGFIX] Reorder processing of TCA select items again".

The function call in TcaSelectItems.php line 87:

$result['databaseRow'][$fieldName] = $this->processSelectFieldValue($result, $fieldName, $staticValues);

changed there to:
$result['databaseRow'][$fieldName] = $this->processSelectFieldValue($result, $fieldName, $itemArray);

$staticValues is empty, but $itemArray is filled in my case with all available items - and compared in AbstractDataProvider to the $currentDatabaseValueArray which holds the number of relations for MM select fields.

    protected function processSelectFieldValue(array $result, $fieldName, array $staticValues)
    {
        $fieldConfig = $result['processedTca']['columns'][$fieldName];

        $currentDatabaseValueArray = array_key_exists($fieldName, $result['databaseRow']) ? $result['databaseRow'][$fieldName] : [];
        $newDatabaseValueArray = [];

        // Add all values that were defined by static methods and do not come from the relation
        // e.g. TCA, TSconfig, itemProcFunc etc.
        foreach ($currentDatabaseValueArray as $value) {
            if (isset($staticValues[$value])) {
                $newDatabaseValueArray[] = $value;
            }
        }

As a result the MM select field gets as additional item the record with uid == number of relations, which can not be deleted.


Related issues

Related to TYPO3 Core - Bug #85142: Recent reordering of TCA select items processing makes it impossible to post-process foreign_table itemsClosed2018-06-02

Actions
Related to TYPO3 Core - Bug #89998: Problem in TCA with type select if MM relation is usedUnder ReviewGeorg Ringer2019-12-20

Actions
Related to TYPO3 Core - Bug #90999: selectMultipleSideBySide adds non selected itemsClosed2020-04-11

Actions
Has duplicate TYPO3 Core - Bug #91062: MM select displays not saved items in 9.5.15Closed2020-04-16

Actions
#1

Updated by Benni Mack 8 months ago

  • Related to Bug #85142: Recent reordering of TCA select items processing makes it impossible to post-process foreign_table items added
#2

Updated by Joschi Kuphal 8 months ago

  • TYPO3 Version changed from 9 to 10

I can confirm similar behaviour for 10.3, but I didn't have the chance to investigate further by now.
Respectively: As soon as the additional record gets saved along with the real selection, the number of MM records increases by one, which potentially adds another record and so on. The erroneous records can be deleted though (but get re-added as soon as the form reloads).

#3

Updated by Martin Weymayer 8 months ago

Same problem occurs, if you use itemsProcFunc and fill selectable items with custom database query. The item with the "id" of number of selected items is also added to selected and you can not delete it. So for example if you have added product with id 5,6,7 and 8, the product with id 4 is also added to selected. This bug is already since 7.6

#4

Updated by Gerrit Code Review 8 months ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64059

#5

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64062

#6

Updated by Gerrit Code Review 8 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64062

#7

Updated by Sebastian Lechenbauer 8 months ago

"As soon as the additional record gets saved along with the real selection, the number of MM records increases by one, which potentially adds another record and so on."
I can confirm this. That is quite problematic, as by repeated saving the MM relations are completely changed - unnoticed by the editor.
Patch set 2 solves the problem for me!

#8

Updated by Gerrit Code Review 8 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64062

#9

Updated by Ephraim Härer 8 months ago

Gerrit Code Review wrote:

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64062

For me this patch worked as expected.
Had also the problem with a MM relation table configured in a TCA field:

'myfield' => [
    'exclude' => 1,
    'displayCond' => 'mydisplaycondition',
    'label' => 'my label',
    'config' => [
        'type' => 'select',
        'renderType' => 'selectMultipleSideBySide',
        'foreign_table' => 'tx_foreign_table',
        'foreign_table_where' => ' AND tx_foreign_table.deleted=0 ORDER BY tx_foreign_table.field',
        'MM' => 'tx_myext_foreign_mm',
        'maxitems' => 9,
        'size' => 9,
        'enableMultiSelectFilterTextfield' => true,
        'fieldControl' => [
            'editPopup' => [
                'disabled' => false,
            ],
            'addRecord' => [
                'disabled' => true,
            ],
            'listModule' => [
                'disabled' => true,
            ],
        ],
        'fieldWizard' => [
            'localizationStateSelector' => [
                'disabled' => true,
            ],
        ],
        'localizeReferencesAtParentLocalization' => false,
        'disableNoMatchingValueElement' => true,
    ]
],

#10

Updated by Ephraim Härer 8 months ago

  • Related to Bug #89998: Problem in TCA with type select if MM relation is used added
#11

Updated by Georg Ringer 8 months ago

  • TYPO3 Version changed from 10 to 9
#12

Updated by Christian Eßl 8 months ago

  • Priority changed from Should have to Must have
  • Target version set to next-patchlevel
#13

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64102

#14

Updated by Christian Eßl 8 months ago

  • Related to Bug #90999: selectMultipleSideBySide adds non selected items added
#15

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64134

#16

Updated by Tobi Kretschmann 8 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#17

Updated by Georg Ringer 8 months ago

  • Has duplicate Bug #91062: MM select displays not saved items in 9.5.15 added
#18

Updated by Benni Mack 7 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF