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

CommentFileSizeAuthor
form-display-error.patch760 bytesmarounmt
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    marounmt created an issue. See original summary.

    avpaderno’s picture

    Version: 4.0.0-alpha6 » 4.x-dev
    Status: Patch (to be ported) » Active
    avpaderno’s picture

    Assigned: marounmt » Unassigned
    Status: Active » Needs review
    averagejoe3000’s picture

    Status: Needs review » Reviewed & tested by the community

    I was getting the same error when setting conditionals on fields in paragraphs. I applied the patch and no longer receive the error and conditionals are working as expected.

    avpaderno’s picture

    Status: Reviewed & tested by the community » Needs work
    Issue tags: +Needs merge request

    Since patches are no longer supported, a merge request should be provided.