Call to a member function getComponent() on null when handling paragraphs with default form display mode

Created on 17 February 2025, about 2 months ago
Updated 27 February 2025, about 2 months ago

Problem/Motivation

After upgrading from `conditional_fields 4.x-alpha5` to `4.x-alpha6`, an error occurs when handling paragraphs in the `ConditionalFieldsFormHelper` class.

Steps to reproduce

1. Use a paragraph field with conditional fields enabled.
2. Ensure no specific form mode is explicitly selected.
3. Attempt to use the conditional logic that depends on the paragraph field.
4. The following error occurs:

Error : Call to a member function getComponent() on null in Drupal\conditional_fields\ConditionalFieldsFormHelper->getState() (ligne 371 de /var/www/preprod_filiale/releases/20250117120019Z/web/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).

Proposed resolution

- The issue occurs because `$form_display->getMode()` returns the first unchecked form display mode instead of the default when no specific form mode is selected.
- This causes `$form_display` to be `null`, leading to an error when calling `getComponent()`.
- A patch has been provided to ensure that the correct form display mode is used, preventing null references.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇱🇧Lebanon marounmt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024