Steps to reproduce

  • Install Drupal 8.5.0 or later, with the Standard profile
  • Go to /admin/structure/block/manage/bartik_tools, note that 3 sections appear under Visibility (Content types, Pages, Roles)
  • Go to /admin/config/people/accounts/fields/user.user.user_picture and make the user picture a Required field
  • Go back to /admin/structure/block/manage/bartik_tools

Expected:
All 3 sections are present under Visibility
Actual:
The "Roles" section is missing

Problem/Motivation

Since 8.5.0, objects are validated when they are checked to see if they satisfy the requirement of a given context.

A required field without a value is invalid. If the current user's account is invalid, any object with a required context of "current user" will fail.

Proposed resolution

Log the failures, allowing site builders to fix the violations.

Remaining tasks

Write tests

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JordiK created an issue. See original summary.

JordiK’s picture

To narrow the problem a bit, I did some further investigations. They showed, that the function buildVisibilityInterface in block\src\BlockForm.php is returning the following condition_ids:
entity_bundle:group
entity_bundle:node
rules_data_is_empty
current_theme
request_path
A condition_id "user_role" is missing (it is returned in older versions, e.g. 8.4.4. though). I hard coded the "user_roles" condition_id in the function - the tab "Roles" appeared correctly with all settings before the update to 8.5.0 also being correct. So the problem is "just" in the returned values from the context.

cilefen’s picture

Issue tags: +8.5.0 update
cilefen’s picture

FWIW the last time BlockForm::buildVisibilityInterface itself changed was #2632434: Conditions are not limited by available contexts. which should have been in 8.2.x, so maybe some other bug has been exposed?

nottaken’s picture

Same issue for me. I've been hunting for solutions and attempting to recreate with fresh installs of 8.4 then updating to 8.5, but not able to recreate the bug yet. Resaving the block doesn't seem to affect role visibility settings already saved.

cilefen’s picture

Could there be contributed modules playing a role here? That's an unintentional pun but I'll leave it.

JordiK’s picture

Well, it was working with all the contrib modules just before the upgrade, so...

cilefen’s picture

Did you upgrade contrib modules too? We have had cases in the past of contrib modules misusing APIs but the bugs this caused only surfaced in later versions.

I am adding the NSTR tag because as per #5 it is not consistently reproducible.

steveoriol’s picture

Same issue for me. I also done the media-entity upgrade to the media core, but I do not know if the the Block visibility setting tab for Roles worked before that...
I also tried to use the module "block_visibility_groups" to test if it works with, but the group of blocks with roles constraint won't display...

It's weird, I use Drupal in multi-sites and some I have the tab "Roles" but not on others ... and I have the same modules installed.
There is also no error in the logs.
I do not understand anymore...

Suvikki’s picture

I have the same problem, the roles tab is missing. I have installed Drupal 8.5.0 with some contributed modules, but I'm using the same modules + many others in my local test environment that I have upgraded to 8.5.0 and the problem doesn't exist there.

JordiK’s picture

Did you had any of these modules installed before upgrading to Drupal 8.5.0?
- Commerce
- Page Manager
- Webform

nottaken’s picture

I don’t use those modules in #11. Are you suggesting those are causing the issue?

arnaud-brugnon’s picture

I have the same issue.
And i don't think this is about other modules or upgrading path.

I don't have this and i just start a new project in 8.5

sureshcj’s picture

FileSize
60.05 KB
82.28 KB

Hi All,

I have upgrading the Drupal 8.4.2 to 8.5.0.
But the roles tab shows fine on block configuration page.
Please find the attachments.

akorkot’s picture

Hi All,

I have the same issue, I have upgrading the Drupal 8.4.2 to 8.5.0.
I have group module installed in my Drupal Site.

Madis’s picture

I ran into this problem when upgrading from 8.5.0-rc1 to 8.5.0, but it included some contrib projects as well. Based on https://www.drupal.org/forum/support/post-installation/2018-03-16/visibi... and #13 it seems like the issue can also appear on fresh 5.0 installs.

Created a temporary solution based on #2 until a proper fix is found.

nottaken’s picture

The patch in #16 seems to bring the roles tab back for me. Thanks Madis for sharing.

Berdir’s picture

What kind of gathered contexts do you have? is there a difference between sites where it works and others where it doesn't?

diona’s picture

Confirm same issue on a fresh 8.5.0 install #13
Also for me patch #16 bring roles tab back. Thanks Madis

sureshcj’s picture

FileSize
54.93 KB

Hi diona,

I was tested fresh 8.5.0 install, It's working fine and shows the role tab for me.

Madis’s picture

If there's varied results with new installs could the difference be related to the chosen installation profile or some other setting (don't have time to dig further into this myself right now sadly)?

cilefen’s picture

I assume #2955370: Block visibility setting tab for Content types not showing anymore after Drupal 8.5.0 upgrade is likely the same problem. If anyone disagrees, reopen it

Madis’s picture

Managed to track the problem down.

Steps to reproduce:
1. Install Drupal 8.
2. Check random block's configuration -> Roles tab exists.
3. On "admin/config/people/accounts/fields/user.user.user_picture" url check "Required field" and save (alternatively just add a required field - "admin/config/people/accounts/fields/add-field").
4. Check random block's configuration -> Roles tab is gone.

Easiest and best solution until the bug gets fixed: go edit and save your profile so that there are no validation errors with it.

So the current user's profile is being validated for the roles tab to show up which makes no sense and didn't happen with earlier core versions. With Drupal 8.4.5 the "getMatchingContexts" function (in core/lib/Drupal/Core/Plugin/Context/ContextHandler.php) returned TRUE, but in 8.5.0 this function calls "isSatisfiedBy" (core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php) which is doing much more than it should in this case. $validator->validate returns the current user's profile errors leading to FALSE being returned and the roles tab won't be displayed.

cilefen’s picture

I just commented on #2671964: ContextHandler cannot validate constraints to draw some attention here.

nottaken’s picture

Issue tags: -Needs steps to reproduce +It can be reproduce

See steps in comment #23

tim.plunkett’s picture

Version: 8.5.0 » 8.6.x-dev
Component: block.module » plugin system
Issue summary: View changes
Status: Active » Needs review
Issue tags: -It can be reproduce
FileSize
913 bytes

The steps to reproduce in #23 are accurate: you are purposefully causing your user account to fail validation. Adding a user picture would fix the problem.

In fact, we can log every violation that would cause this bug, thereby addressing #2955370: Block visibility setting tab for Content types not showing anymore after Drupal 8.5.0 upgrade as well.

Unfortunately, I don't see a reasonable way to go back to the "invalid objects are okay" approach from before.

Status: Needs review » Needs work

The last submitted patch, 26: 2952962-context-26.patch, failed testing. View results

Suvikki’s picture

I went to edit my user profile settings and for some weird reason Administrator user role checkbox wasn't checked. After I checked it and saved my profile settings, i got the roles tab back.

XTaz’s picture

Thanks Suvikki.
Your tip #28 solved the issue for me too

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
1.07 KB

This might be an actual bugfix here.

tim.plunkett’s picture

The last submitted patch, 31: 2952962-context-31-FAIL.patch, failed testing. View results

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

This seems so sensible and elegant of a way to solve this. I'm super ++ all around.

Eclipse

kle’s picture

Thanks Suvikki.
Your tip #28 worked for me, but first(!) I had to switch off the Administrator role first then activate again - voilà !

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: 2952962-context-31-PASS.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

I credited @cilefen for issue management.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 5d5af494fb to 8.6.x and e3f39f98cc to 8.5.x. Thanks!

  • alexpott committed 5d5af49 on 8.6.x
    Issue #2952962 by tim.plunkett, sureshcj, JordiK, Madis, cilefen: Block...

  • alexpott committed e3f39f9 on 8.5.x
    Issue #2952962 by tim.plunkett, sureshcj, JordiK, Madis, cilefen: Block...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.