Bug #85531

Error with "select" and "group" field using l10n_display "defaultAsReadonly"

Added by Mathias Brodala over 1 year ago. Updated about 1 month ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2018-07-10
Due date:
% Done:

0%

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

Description

When editing a translated record which contains a group field whose l10n_display is configured as defaultAsReadonly an exception occurs:

#1476107295: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php line 120 (More information)

TYPO3\CMS\Core\Error\Exception thrown in file
/.../typo3/sysext/core/Classes/Error/ErrorHandler.php in line 115.

38 TYPO3\CMS\Core\Error\ErrorHandler::handleError(2, "count(): Parameter must be an array or an object that implements Countable", "/.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php", 120, array)
37 count("1")

/.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php:
00118: 
00119:         $selectedItems = $parameterArray['itemFormElValue'];
00120:         $selectedItemsCount = count($selectedItems);
00121: 
00122:         $maxItems = $config['maxitems'];

A similar error occurs a little later on TYPO3v8:

#1476107295: PHP Warning: Invalid argument supplied for foreach() in /.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php line 158 (More information)

TYPO3\CMS\Core\Error\Exception thrown in file
/.../typo3/sysext/core/Classes/Error/ErrorHandler.php in line 107.

17 TYPO3\CMS\Core\Error\ErrorHandler::handleError(2, "Invalid argument supplied for foreach()", "/.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php", 158, array)

/.../typo3/sysext/backend/Classes/Form/Element/GroupElement.php:
00156:             }
00157:         } elseif ($internalType === 'db') {
00158:             foreach ($selectedItems as $selectedItem) {
00159:                 $tableWithUid = $selectedItem['table'] . '_' . $selectedItem['uid'];
00160:                 $listOfSelectedValues[] = $tableWithUid;

The code here expects an array but gets an integer (number of related records) instead.

This is triggered by the SingleFieldContainer which replaces the databaseRow value prepared by TcaGroup with the raw value from defaultLanguageRow in case l10n_display is set to defaultAsReadonly.

This error does not occur on TYPO3v7 but the field is empty instead there.

This can be reproduced e.g. with the following steps:

  1. Add 'l10n_display' => 'defaultAsReadonly' to $GLOBALS['TCA']['tt_content']['columns']['file_collections']
  2. Create an empty file collection on a page
  3. Add a File links content element to that page and select the created file collection
  4. Translate the page and the File links content element
  5. Edit the translated File links content element and see the error

Related issues

Duplicated by TYPO3 Core - Bug #84550: "l10n_display = defaultAsReadonly" throws exception for "type = group" elements Closed 2018-03-28

History

#1 Updated by Mathias Brodala over 1 year ago

  • Description updated (diff)

#2 Updated by Mathias Brodala over 1 year ago

  • Subject changed from Error with "db" field using l10n_display "defaultAsReadonly" to Error with "group" field using l10n_display "defaultAsReadonly"
  • Description updated (diff)

#3 Updated by Mathias Brodala over 1 year ago

  • Description updated (diff)

#4 Updated by Mathias Brodala over 1 year ago

  • Description updated (diff)

#5 Updated by Mathias Brodala over 1 year ago

  • Description updated (diff)
  • Is Regression set to Yes

#6 Updated by Mathias Brodala over 1 year ago

  • Subject changed from Error with "group" field using l10n_display "defaultAsReadonly" to Error with "select" and "group" field using l10n_display "defaultAsReadonly"

I noticed a similar issue today: if a select field is configured with defaultAsReadonly it will be displayed as readonly in translations just fine.

However the field value of the default language row is rendered as hidden field next to the visible readonly field. Since the field value in the default language row is unprocessed as described here it contains the number of related records. This in turn leads to a broken relation as soon as you save a translation since the original number of related records is now interpreted as foreign record UID.

How to reproduce:

1. Have a record and create a translation of this record
2. Have a field with 'l10n_display' => 'defaultAsReadonly' in this record
3. Select a related record (with a UID > 1 to make it clearer) in the default language
4. Switch to the translation
5. Save the translation

After this, the translation will have the related record with UID 1 selected since the number of related records in the default language is 1. If you have a multi-select you can see the same with multiple records: if you select 2 related records in the default language, the related record with UID 2 is selected in the translation, etc.

#7 Updated by Mathias Brodala over 1 year ago

And another one: selectSingle fields configured with defaultAsReadonly don't display the value of the default language in translations. This is due to the itemFormElValue being a plain number instead of an array which is the case without defaultAsReadonly.

#8 Updated by Mathias Brodala about 1 year ago

  • Duplicated by Bug #84550: "l10n_display = defaultAsReadonly" throws exception for "type = group" elements added

#9 Updated by Thomas Deinhamer about 1 month ago

Encountering this with TYPO3 v9 too.

Also available in: Atom PDF