TypeError: array_intersect(): Argument #1 ($array) must be of type array, null given em array_intersect()

Created on 17 March 2024, 3 months ago
Updated 3 April 2024, 3 months ago

Problem/Motivation

When using an entity reference view to load terms, we get a WSOD when editing node view mode.

Steps to reproduce

This is my use case, but I believe it can be reproducible with other cases:

- Create a vocabulary V and add terms VA, VB, VC
- Create a taxonomy view W of type Entity Reference, that is listing all V terms
- Create a paragraph P with a field F of type Taxonomy Reference that references W
- Create a node N with a paragraph field referencing P

Now, edit the display mode using Layout Builder.

The WSOD appears, before a warning and a fatal php error.

Proposed resolution

On src/Service/AccessChecker.php line 203 make sure that ['target_bundles'] exists.

If we debug the $field_definition->getSetting() we get this:

Array
(
    [view] => Array
        (
            [view_name] => documentos_taxonomia_aux
            [display_name] => entity_reference_1
            [arguments] => Array
                (
                )

        )

)

and because we are using an entity reference, there is no target_bundle chosen on the taxonomy field.

I haven't path'ed it because I don't know where is the best place to check field setting, so I leave it here for whom is more used to PbT.

🐛 Bug report
Status

Needs review

Version

3.1

Component

Code

Created by

🇵🇹Portugal jrochate

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

Merge Requests

Comments & Activities

  • Issue created by @jrochate
  • 🇵🇹Portugal jrochate

    If there is no suggestion from someone more used to PbT, I will post my own patch in a couple of days.

  • 🇮🇳India dineshkumarbollu

    @jrochate

    Added condition to fix the issue, please review and test the patch.Thanks

  • 🇵🇹Portugal jrochate

    I'm sorry, but I think that's not the solution.

    You would have a warning about the non existing dimension of the array.

    Also I don't the real implications of having the $field_target_bundles empty processed, instead of just skipping the code when empty.

    I think we must wait for someone with a better knowledge about PbT. This is an access module, we shouldn't patch it to solve basic PHP errors without knowing the implications of some patch decisions.

  • First commit to issue fork.
  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany marcoliver Neuss, NRW, Germany

    I have created a MR with a fix similar to what @dineshkumarbollu proposed, but also avoiding the warning @jrochate mentioned.

    I believe providing an empty fallback value here in case there are no target_bundles defined is fine. $field_target_bundles is used for one specific check only, which we're not going to pass anyway if $field_target_bundles has an empty value. Afterwards it is not used again.

    I played with the scenario a bit and the change does fix the error but does not seem to introduce any new issues.

    I'd greatly appreciate it if somebody else could give the MR a quick look.

Production build 0.69.0 2024