Problem/Motivation

TypeError: Unsupported operand types: array + null in Drupal\field_ui\Form\EntityViewDisplayEditForm->Drupal\field_ui\Form\{closure}() (line 166 of core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php).

The actual issue is coming from the Linked Field module, however, this should be better handled. From what I can see in the code they were close.

Steps to reproduce

  1. Install and enable 'linked_field' module
  2. Add a 'link' field to an entity type
  3. Go to entity types manage display
  4. Presto!!

Proposed resolution

Change:

$settings_form[$module] = ($settings_form[$module] ?? []) + ($hook(
   $plugin,
   $field_definition,
    $this->entity->getMode(),
    $form,
    $form_state,
)) ?? [];

to:

$settings_form[$module] = ($settings_form[$module] ?? []) + ($hook(
   $plugin,
   $field_definition,
    $this->entity->getMode(),
    $form,
    $form_state,
) ?? []);

Issue fork drupal-3552531

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

cbstuart created an issue. See original summary.

cbstuart’s picture

cbstuart’s picture

Issue summary: View changes
cbstuart’s picture

Issue summary: View changes
cilefen’s picture

Version: 11.2.x-dev » 11.x-dev
Issue tags: +Needs merge request
awasson’s picture

Yes, the resolution proposed by @cbstuart resolves the issue.

vitaliyb98’s picture

Also received this error. Provided solution works for me.

cilefen’s picture

Status: Active » Needs work
Issue tags: -Needs merge request +Needs tests

So there is a subtle syntax bug here. Can we get an automated test that triggers the bug?

awasson’s picture

Priority: Normal » Major

I'm bumping this to Major as it makes it impossible to administrate production websites without patching (not possible on some hosts like Pantheon). I would bump to critical but that's just my particular situation.

EDIT: For clarification, by Major, I mean that none of my Display settings are available for content or paragraphs.

The fix that has been proposed does prevent the issue.

Cheers,
Andrew

awasson’s picture

@cilefen, are you suggesting that the proposed fix introduces a subtle syntax bug? I'm trying to identify where it exists.

Where the existing code positions the null coalescing operator positioned leads to the TypeError mentioned. The updated version ensures that:

1) If $settings_form[$module] is not set, it defaults to an empty array
2) If the $hook() method call returns null, it's replaced with an empty array
3) The arrays are then safely merged using the + operator

I must have missed something. Can you elaborate so we can get this resolved?

Cheers,
Andrew

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

tobiasb’s picture

Title: Unsupported operand types: array + null in Drupal\field_ui\... » Unsupported operand types: array + null when calling field_formatter_third_party_settings_form hook
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests

Just try:

Fatal error:

[] + NULL ?? [];

Fixed:

[] + (NULL ?? []);
astonvictor’s picture

Status: Needs review » Needs work

[ignore]

astonvictor’s picture

Status: Needs work » Needs review

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

ankitv18’s picture

Status: Needs review » Reviewed & tested by the community

Rebasing the MR make the pipeline pass.
changes are quite straightforward, hence moving into RTBC

  • catch committed b4cd8ebc on 11.3.x
    fix: #3552531 Unsupported operand types: array + null when calling...

  • catch committed 22fac0f4 on 11.x
    fix: #3552531 Unsupported operand types: array + null when calling...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.