Skip to content

PHP Warning: Undefined array key 'flexParentDatabaseRow' in FlexFormUserFunctions #4616

@magicsunday

Description

@magicsunday

Description

FlexFormUserFunctions::getFacetFieldsFromSchema() and FlexFormUserFunctions::getAvailableTemplates() access $parentInformation['flexParentDatabaseRow'] without checking if the key exists, causing PHP warnings:

PHP Warning: Undefined array key "flexParentDatabaseRow" in
Classes/System/UserFunctions/FlexFormUserFunctions.php line 45

PHP Warning: Undefined array key "flexParentDatabaseRow" in
Classes/System/UserFunctions/FlexFormUserFunctions.php line 142

Steps to Reproduce

  1. Open a content element with a Solr plugin in the TYPO3 backend
  2. The FlexForm rendering triggers getFacetFieldsFromSchema() and getAvailableTemplates()
  3. Under certain conditions (e.g. new content element, or specific TCA context), flexParentDatabaseRow is not set in $parentInformation

Expected Behavior

No PHP warning. The methods should check for the key's existence before accessing it, similar to the is_array($pageRecord) guard that already exists a few lines later.

Actual Behavior

PHP Warning is logged to sys_log for every affected FlexForm render. In our case, 169 warnings were logged in a single backend session.

Suggested Fix

Add a null-coalescing check before accessing the key:

// Line 45 (getFacetFieldsFromSchema)
$pageRecord = $parentInformation['flexParentDatabaseRow'] ?? null;

// Line 142 (getAvailableTemplates)  
$pageRecord = $parentInformation['flexParentDatabaseRow'] ?? null;

The existing if (!is_array($pageRecord)) guards on the subsequent lines would then handle the null case correctly.

Environment

  • EXT:solr version: 13.1.1
  • TYPO3 version: 13
  • PHP version: 8.4

Metadata

Metadata

Assignees

No one assigned

    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