Project

General

Profile

Actions

Bug #85531

closed

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

Added by Mathias Brodala over 6 years ago. Updated almost 3 years ago.

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

0%

Estimated time:
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 1 (0 open1 closed)

Has duplicate TYPO3 Core - Bug #84550: "l10n_display = defaultAsReadonly" throws exception for "type = group" elementsClosed2018-03-28

Actions
Actions #1

Updated by Mathias Brodala over 6 years ago

  • Description updated (diff)
Actions #2

Updated by Mathias Brodala over 6 years ago

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

Updated by Mathias Brodala over 6 years ago

  • Description updated (diff)
Actions #4

Updated by Mathias Brodala over 6 years ago

  • Description updated (diff)
Actions #5

Updated by Mathias Brodala over 6 years ago

  • Description updated (diff)
  • Is Regression set to Yes
Actions #6

Updated by Mathias Brodala about 6 years 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.

Actions #7

Updated by Mathias Brodala about 6 years 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.

Actions #8

Updated by Mathias Brodala about 6 years ago

  • Has duplicate Bug #84550: "l10n_display = defaultAsReadonly" throws exception for "type = group" elements added
Actions #9

Updated by Thomas Deinhamer about 5 years ago

Encountering this with TYPO3 v9 too.

Actions #10

Updated by Chris Müller about 4 years ago

Problem occurs also in TYPO3 10.4.6 (have it in a group field).

Actions #11

Updated by Oliver Bartsch almost 3 years ago

  • Status changed from New to Closed

Hi, this has been fixed with #89152. Therefore, I'll close this issue now. In case you still encounter similar problems, please create a new issue with reference to this one.

Actions #12

Updated by Mathias Brodala almost 3 years ago

Oliver Bartsch wrote in #note-11:

Hi, this has been fixed with #89152. Therefore, I'll close this issue now. In case you still encounter similar problems, please create a new issue with reference to this one.

Sounds like the solution indeed, I need to get back to where I discovered this. In any case thanks for the fix!

Actions

Also available in: Atom PDF