Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#31 | 2952962-context-31-PASS.patch | 2.41 KB | tim.plunkett |
#31 | 2952962-context-31-FAIL.patch | 1.34 KB | tim.plunkett |
#30 | 2952962-context-29.patch | 1.07 KB | tim.plunkett |
#26 | 2952962-context-26.patch | 913 bytes | tim.plunkett |
#20 | Configure block Test.png | 54.93 KB | sureshcj |
Comments
Comment #2
JordiK CreditAttribution: JordiK commentedTo 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.
Comment #3
cilefen CreditAttribution: cilefen as a volunteer commentedComment #4
cilefen CreditAttribution: cilefen as a volunteer commentedFWIW 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?
Comment #5
nottaken CreditAttribution: nottaken commentedSame 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.
Comment #6
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedCould there be contributed modules playing a role here? That's an unintentional pun but I'll leave it.
Comment #7
JordiK CreditAttribution: JordiK commentedWell, it was working with all the contrib modules just before the upgrade, so...
Comment #8
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedDid 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.
Comment #9
steveoriolSame 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...
Comment #10
Suvikki CreditAttribution: Suvikki as a volunteer commentedI 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.
Comment #11
JordiK CreditAttribution: JordiK commentedDid you had any of these modules installed before upgrading to Drupal 8.5.0?
- Commerce
- Page Manager
- Webform
Comment #12
nottaken CreditAttribution: nottaken commentedI don’t use those modules in #11. Are you suggesting those are causing the issue?
Comment #13
arnaud-brugnon CreditAttribution: arnaud-brugnon commentedI 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
Comment #14
sureshcj CreditAttribution: sureshcj at DrupalPartners commentedHi 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.
Comment #15
akorkot CreditAttribution: akorkot commentedHi 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.
Comment #16
Madis CreditAttribution: Madis at ADM Interactive commentedI 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.
Comment #17
nottaken CreditAttribution: nottaken commentedThe patch in #16 seems to bring the roles tab back for me. Thanks Madis for sharing.
Comment #18
BerdirWhat kind of gathered contexts do you have? is there a difference between sites where it works and others where it doesn't?
Comment #19
diona CreditAttribution: diona commentedConfirm same issue on a fresh 8.5.0 install #13
Also for me patch #16 bring roles tab back. Thanks Madis
Comment #20
sureshcj CreditAttribution: sureshcj at DrupalPartners commentedHi diona,
I was tested fresh 8.5.0 install, It's working fine and shows the role tab for me.
Comment #21
Madis CreditAttribution: Madis at ADM Interactive commentedIf 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)?
Comment #22
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedI 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
Comment #23
Madis CreditAttribution: Madis as a volunteer commentedManaged 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.
Comment #24
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedI just commented on #2671964: ContextHandler cannot validate constraints to draw some attention here.
Comment #25
nottaken CreditAttribution: nottaken commentedSee steps in comment #23
Comment #26
tim.plunkettThe 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.
Comment #28
Suvikki CreditAttribution: Suvikki as a volunteer commentedI 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.
Comment #29
XTazThanks Suvikki.
Your tip #28 solved the issue for me too
Comment #30
tim.plunkettThis might be an actual bugfix here.
Comment #31
tim.plunkettHere's a test.
Comment #33
EclipseGc CreditAttribution: EclipseGc at Acquia commentedThis seems so sensible and elegant of a way to solve this. I'm super ++ all around.
Eclipse
Comment #34
kle CreditAttribution: kle commentedThanks Suvikki.
Your tip #28 worked for me, but first(!) I had to switch off the Administrator role first then activate again - voilà !
Comment #36
tim.plunkettComment #37
alexpottI credited @cilefen for issue management.
Comment #38
alexpottCommitted and pushed 5d5af494fb to 8.6.x and e3f39f98cc to 8.5.x. Thanks!