Problem/Motivation
In Views, I cannot use a "View field" source in a component that is nested inside another component.
I’m using Drupal 11.1.2.
Steps to reproduce
Create a new view working on a content type and use "Component (UI Patterns)" as row view style plugin and add some fields.

On the plugin options, use an SDC component with slots (here the "Magazine card" component which has "Card header", "Card content" and "Card footer" slots).

In one slot (here the "Card content" slot), insert another component (here the "Heading" component whis has "Content" slot)

Add a "view field" source to the slot (here the "title" field is added to the "Content" slot of the "Heading" component)

When applying the modifications, an error message stating "array_keys(): Argument #1 ($array) must be of type array, null given" appears right under the component selector.

| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Screenshot 2025-02-12 at 23.27.22.png | 1.16 MB | smovs |
| #8 | Screenshot 2025-02-12 at 23.25.09.png | 1.25 MB | smovs |
| 04-error-message.png | 11.76 KB | zigazou | |
| 03-view-field-selection.png | 18.04 KB | zigazou | |
| 02-nested-component.png | 21.67 KB | zigazou |
Issue fork ui_patterns-3506138
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:
- 2.0.x
changes, plain diff MR !339
- 3506138-unable-to-use
compare
Comments
Comment #3
zigazou commentedThe proposed patch works for my case but I’m really not sure if this is what needs to be done.
Comment #4
pdureau commentedThanks so much. Can you do a MR?
Comment #6
zigazou commentedMR has been done.
Comment #7
pdureau commentedComment #8
smovs commentedHi @zigazou!
Thank you for your contribution.
I confirm that this fix resolves the issue with the “View field” in the nested component within Views.
It seems that when we use nested components, the View’s query may not have been executed at that point, resulting in an empty
$viewin$this. Calling$view->build();fixes this by rebuilding the View and fetching the data successfully.However, I’m not entirely sure about the performance impact of this approach. Perhaps we could add a workaround to check the state of the View and apply this fix only when necessary.
I added screenshots with the View state without the fix and with it.
Comment #9
pdureau commentedThanks so much @smovs
Hi Christian, can you check this?
Comment #10
zigazou commentedThe first lines of the
buildmethod are the following:Therefore calling the
buildmethod on an already built view should not have a performance impact.On another side, this might hide an incorrect view manipulation along the process.
Comment #11
pdureau commentedMikael ?
Comment #12
pdureau commentedComment #13
pdureau commentedComment #14
pdureau commentedCurrently rebasing.
Comment #15
pdureau commentedComment #17
pdureau commentedComment #18
pdureau commentedComment #20
pdureau commented