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.
The view

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).
The main component

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

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

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.
The error message

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

zigazou created an issue. See original summary.

zigazou changed the visibility of the branch 3506138-unable-to-use to hidden.

zigazou’s picture

The proposed patch works for my case but I’m really not sure if this is what needs to be done.

pdureau’s picture

Title: Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given » [2.0.1] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given
Status: Active » Needs work

Thanks so much. Can you do a MR?

zigazou’s picture

MR has been done.

pdureau’s picture

Status: Needs work » Needs review
smovs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.25 MB
new1.16 MB

Hi @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 $view in $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.

pdureau’s picture

Assigned: Unassigned » christian.wiedemann

Thanks so much @smovs

However, I’m not entirely sure about the performance impact of this approach.

Hi Christian, can you check this?

zigazou’s picture

The first lines of the build method are the following:

    if (!empty($this->built)) {
      return;
    }

Therefore calling the build method on an already built view should not have a performance impact.

On another side, this might hide an incorrect view manipulation along the process.

pdureau’s picture

pdureau’s picture

Title: [2.0.1] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given » [2.0.2] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given
pdureau’s picture

Title: [2.0.2] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given » [2.0.4] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given
pdureau’s picture

Title: [2.0.4] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given » [2.0.5] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given
Assigned: just_like_good_vibes » pdureau

Currently rebasing.

pdureau’s picture

Title: [2.0.5] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given » [2.0.4] Unable to use View field source in a component nested in a component with error message array_keys(): Argument #1 ($array) must be of type array, null given

pdureau’s picture

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Reviewed & tested by the community » Fixed

  • pdureau committed ef11c316 on 2.0.x authored by zigazou
    Issue #3506138 by zigazou, smovs, just_like_good_vibes: Force view to be...
pdureau’s picture

Status: Fixed » Closed (fixed)