Problem/Motivation

When using inline blocks in Layout Builder for GraphQL to create draft versions of content the draft version of a block returns null. This causes a query error.
When you load a node using the latest revision parameter you get the correct node revision, you even get the correct block configuration revision, however when you try to load the block content it fails.
After deep diving and trying to track this down it looks like it comes from the BlockContentEntityLoad.php class.

$access = $entity->access('view', NULL, TRUE);

That access check returns forbidden because the parent entity isn't in the access context.
The current entity (node) is part of the layout_builder_contexts but that isn't added to the block entity prior to the access check.

Steps to reproduce

Use GraphQL compose with Layout Builder to create content on nodes.
Use node revisions workflow.
Add a node with a block on it and publish.
Update the node and update the block in the node and set to Draft.
Query that route using the "latest" revision parameter.

Proposed resolution

Get the current node/entity from context.
Add that to the block entity as an access dependency.

Remaining tasks

Create MR with fix.

User interface changes

none

API changes

draft blocks return draft content

Data model changes

none

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

jlockhart created an issue. See original summary.

jlockhart’s picture

StatusFileSize
new125.72 KB

After getting the context and adding the access dependency this is what the feed looks like.

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

almunnings’s picture

Ok, so no troubles with the approach.
The class moved in 11.2 which gives me a nice ugly block of code in the 3.x release

Question now is around access.

  if ($parent_entity instanceof AccessibleInterface) {
    $entity->setAccessDependency($parent_entity);
  }

Replacing the block's access with the parent entities access for any block_content could be an issue? Perhaps if blocks are conditionally accessible. Do we need to check for edit access to the parent, instead of view access?

jlockhart’s picture

Thanks for updating this.
I'm definitely not an expert on this but...
As I understand it that access check is specifically for things like layout builder inline blocks where their visibility is depended on the users access to the parent entity/node. The check(s) above that should limit this to layout builder inline blocks only, rather than reusable/standard blocks.
Certainly worth testing that though.

almunnings’s picture

Yeah that looks legit.

The same pattern can be seen in web/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php onBuildRender

It's got the same block of functionality for setAccessDependency on the parent.

I'm happy with this, will merge to v3

  • almunnings committed 2aec1a57 on 3.0.x
    fix: #3556558 Draft layout builder blocks cause error and return null...

almunnings changed the visibility of the branch 3.0.x to hidden.

almunnings’s picture

Rebased the 2.4.x to CI updates, and added the 11.2 deprecation check.

almunnings’s picture

Version: 2.4.0 » 3.0.0-alpha1
Status: Active » Needs review

Throwing back to you for review on 2.4.x

If it works, its merged

almunnings’s picture

Status: Needs review » Fixed

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.