Problem/Motivation

On PHP 8.4, several functions in field_group declare a typed parameter with a = NULL default but no explicit nullable type. PHP 8.4 deprecates implicitly marking a parameter as nullable, so these emit deprecation warnings, for example:

Drupal\field_group\FormatterHelper::formProcess(): Implicitly marking parameter $form_state as nullable is deprecated, the explicit nullable type must be used instead

Affected signatures:

  • FormatterHelper::formProcess() ($form_state)
  • field_group_form_process() ($form_state)
  • field_group_field_group_form_process_build_alter() ($form_state)
  • field_group_fields_nest() ($vars)
  • field_group_field_layout_fields_nest() ($vars)
  • field_group_group_save() ($display)

Steps to reproduce

Run field_group on PHP 8.4. Any request or cron run that builds an entity form or display with field groups loads the affected files and triggers the warnings in the logs.

Proposed resolution

Add explicit nullable types (?Type $param = NULL) to the affected parameters. See the change in #6.

Remaining tasks

  • Move the patch to a merge request on the issue fork.
  • Review/RTBC
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

raphael.badawi created an issue. See original summary.

avpaderno’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Patch (to be ported) » Needs work
Issue tags: +Needs issue summary update, +PHP 8.1

The issue summary needs to be updated to describe exactly what the bug is.

dineshreddymathuku made their first commit to this issue’s fork.

dineshreddymathuku’s picture

Hi @raphael.badawi did you get any error for PHP 8 compatibility
please provide that error will understand more for that then will do some solution
i saw your patch as well adding (array) problem solved?

swentel’s picture

Triggered a test on 8.1, let's see how field group behaves on that version.

didebru’s picture

Title: PHP 8 compatibility » PHP 8.4 compatibility
Version: 7.x-1.x-dev » 8.x-3.x-dev
StatusFileSize
new2.79 KB

There were a few deprecation warnings.

scontzen’s picture

Assigned: raphael.badawi » Unassigned
Category: Bug report » Task
Issue summary: View changes
Issue tags: -Needs issue summary update

Thanks @didebru for the patch.

Updated the issue summary (re #2) with the actual deprecation messages and the list of affected signatures.

Tested patch #6 (field_group_8_4.patch) on:

  • field_group 8.x-3.6.0 (stable, applies cleanly)
  • Drupal 10.6.10
  • PHP 8.4.18

Before the patch, loading FormatterHelper and field_group.module under E_ALL triggers the implicitly-nullable deprecation for formProcess() and the procedural functions listed in the summary. With the patch applied, the deprecations are gone. Both files load cleanly under E_ALL, php -l passes, and the site renders normally. I also checked the module for any other typed parameter with a = NULL default but no ?, and there aren't any.

I'd leave this at Needs work for now. @didebru, would you want to put your change on the issue fork (3317567-php-8-compatibility) as an MR?

scontzen’s picture

Issue tags: -PHP 8.1 +PHP 8.4
avpaderno’s picture

Issue summary: View changes
dpi’s picture

Even though this patch is still relevant for the last 3.x series stable release, a fix was already applied in #3504453: Fix PHP 8.4.x deprecation and other warnings (PHPStan) to 3.x branch, and the 4.x fork.

The maintainers of Field Group have discontinued 3.x entirely, focusing on 4.x being a drop-in replacement.

This issue is no longer required. Is it possible for collaborators (for which I'm not included) on this issue to receive credit? Then feel free to close.

dpi’s picture

Status: Needs work » Active
anybody’s picture

Version: 8.x-3.x-dev » 4.x-dev

All new bug fixes and features should go into 4.x-dev first, we can still consider backporting some of them to 8.x-3.x if really needed.

anybody’s picture

Status: Active » Needs work

Please prepare a MR against 4.x

avpaderno’s picture

I did not find all the methods/functions listed in the issue summary, but Formatter::formProcess() seems already fixed.

public static function formProcess(array &$element, ?FormStateInterface $form_state = NULL, array &$form = []): array {

$form_state has been explicitly marked nullable.

Comment #10 says a fix has been already applied to the 4.x branch.

anybody’s picture

Status: Needs work » Postponed (maintainer needs more info)

Thanks @avpaderno so maybe this issue is simply outdated?

avpaderno’s picture

It seems it is. The previous comment was stating that and asking for the credits to be given to collaborators.

liam morland’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#3504453: Fix PHP 8.4.x deprecation and other warnings (PHPStan)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.