Problem/Motivation

I try to set field Visibility of a content type based on the User Role. But any role I select, the field disappears for all roles.

Steps to reproduce

  1. Use Display Builder to set the layout of a content type.
  2. Choose a field and set Visibility by User Role.
  3. The field disappears for every role.

Proposed resolution

?

Remaining tasks

Fix the wrong behaviour.

User interface changes

-

API changes

?

Data model changes

?

CommentFileSizeAuthor
#3 Screenshot 2025-12-09 at 23.47.38.png327.21 KByannickoo
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

thamas created an issue. See original summary.

thamas’s picture

I tried it with alpha6, but I received feedback that the problem also exists in the current development version.

yannickoo’s picture

StatusFileSize
new327.21 KB

I was quickly debugging this and found two things:

1. The "Current theme" condition does not come with #empty_option so the first item is always selected, in my case it was already set to Claro which is not what we want.

Over in display_builder_page_layout module there is this code to hide the Current theme condition plugin, should we do the same here?

2. When using Xdebug to check what is going on here I noticed that the entity:user context is required but not found therefore that currently fails completely:

Maybe the fix is super easy, we just need to know how to make the context available 🤓

mogtofu33’s picture

yannickoo’s picture

Alright so it looks like we are missing the context mapping here. There is also #3561312: Page conditions for content type which seems to be the same problem but somewhere else.

Investigating here 🤓

yannickoo’s picture

Status: Active » Needs review

It turned out that the contexts were not working because the gathered_contexts were not including things like the current user context etc. Once that has been adjusted the buildConfigurationForm method is able to automatically provide the context mapping like for the UserRole condition plugin 🤯

Additionally we need to map the context with values in alterElement method.

mogtofu33’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.