When editing a node using Layout Builder, adding a view block of a view display that has contextual arguments causes an AJAX error and a PHP error in Recent log messages.

Steps to replicate

Create a view with a block display of node content where the content type you are filtering the view by has an Entity Reference field to a taxonomy vocabulary. Add a contextual filter of "Content: Has taxonomy term ID". Configure it like this (selecting the vocabulary your field references):

contextual links configuration 1

contextual links configuration 2

contextual links configuration 3

Save the view.

Go to a node with Layout Builder enabled. Add this view block through Layout Builder.

Click "Add Block". This will cause an AJAX error to be logged to your browser console:

ajax error

The form will not visibly submit and the modal window will remain open.

Close the modal window and click "Save Layout". You will see that the block has actually been added successfully and it does appear.

Edit the Layout again. Attempt to add an unrelated block. This will fail with another AJAX error.

Essentially, so long as the view block with the contextual filter exists within Layout Builder, most actions within Layout Builder will fail with AJAX errors.

Check your Recent log messages at /admin/reports/dblog.

You will see this log with severity of Error:

Drupal\Core\Database\InvalidQueryException: Query condition 'taxonomy_term_field_data.name IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 105 of /app/web/core/lib/Drupal/Core/Database/Query/Condition.php).

Try rendering this same view display block using the classic block layout UI at /admin/structure/block/.

It will not cause an AJAX or PHP error to be logged. It will render successfully.

Expected behavior

Layout Builder should render a view block with a contextual filter without error, the same as if it were placed and rendered via the classic block UI at /admin/structure/block/.

Layout Builder should respect the normal process of resolving a contextual filter argument when in Layout edit mode.

In this example, when no contextual filter argument is provided (because Layout Builder gives no field to provide one), the view should default to displaying all content. This is what the view display does when previewing from the views edit form, when placing the view block from /admin/structure/block, when rendering the view block using Twig Tweak, and even when viewing the node the view block has been placed on via Layout Builder. It is only when editing the node Layout using Layout Builder that errors arise.

I'm wondering if this is at all related to: https://www.drupal.org/project/drupal/issues/2921626

Comments

maskedjellybean created an issue. See original summary.

Version: 8.8.1 » 8.8.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

Version: 8.9.x-dev » 9.3.x-dev
Issue tags: +Bug Smash Initiative, +Blocks-Layouts

Thanks for such a detailed bug report

Does this issue still exist?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

leisurman’s picture

My View is using a contextual filter (content id from URL) I added it to Layout builder and I see "Placeholder for the "my view" views block"
and the view does not display any content in preview mode. The view displays fine if I add it to a node that doesn't use Layout builder. I am using Drupal core 9.3.16. Similar issue here: https://www.drupal.org/project/drupal/issues/3196319

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

johnpitcairn’s picture

Status: Active » Closed (outdated)

I don't think this still occurs. Closing as outdated.