Problem/Motivation
When a block gets broken, this message is shown to all users, even anonymous:
This block is broken or missing. You may be missing content or you might need to enable the original module.
Steps to reproduce
Proposed resolution
This message should only be shown to users who have access to edit the block. However, because the block is broken we no longer know the details of the block, so it will be tricky to determine who gets to see the message. At the very least we can hide this from anonymous users.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#51 | 2918149-50-8.9.x.patch | 5.25 KB | longwave |
#41 | 2918149-brokenblock-41-interdiff.txt | 6.8 KB | tim.plunkett |
#41 | 2918149-brokenblock-41.patch | 7.09 KB | tim.plunkett |
#39 | before__patch.jpg | 269.89 KB | ranjith_kumar_k_u |
#39 | after__patch.jpg | 226.57 KB | ranjith_kumar_k_u |
Comments
Comment #2
tim.plunkettAnother idea would be to use trigger_error instead, which can be suppressed on production.
But I definitely agree with the sentiment of the issue! Thanks.
Comment #3
manuel.adanIn addition to a better broken blocks management in core, I just published the fixed block content module that solves the situation. The module provides a type of block based on configuration (the fixed block) that wraps a custom block (the content block). If the content block does not exist, it is created with a default content or empty if no default content was set. Fixed blocks are always present, so no "This block is broken or missing." messages to the users.
Comment #4
dalinBut that's why we can't use trigger_error exclusively, we'll want content editors to see the message.
First patch attempt.
Comment #6
dalinAll those tests intentionally create broken blocks??? That can't be right.
Comment #7
tim.plunkettYes, every test that installs
block_content_test
will get that block.We probably should move the intentionally broken block to another module, and only use it in the tests that explicitly expect it.
Comment #8
froboyI've tested this patch and it works well to hide the message from users who shouldn't see them.
Manual tests:
- admin: can see broken block
- user with block admin: can see broken block
- user without block admin: can't see broken block
- authenticated user: can't see broken block
- anonymous user: can't see broken block
Do we need to deal with the test issue to call this RTBC or can it move forward?
Comment #9
dalinYup. We can't commit broken tests.
Comment #10
anil.gangwal CreditAttribution: anil.gangwal at Publicis Sapient for Publicis Sapient commentedSimplified the https://www.drupal.org/project/drupal/issues/2918149#comment-12333965 patch As both error message should not trigger simultaneously for and also change message for anonymous user.
Comment #11
dalin@anil I disagree. The whole point is not to advertise to anonymous users that something is broken, only to people who can do something about it.
The
trigger_error()
is so that when an anonymous user sees the block, an error shows up in watchdog, the$build += $this->brokenMessage();
is so needed for two reasons:Comment #14
nikunjkotechaSimple patch to avoid showing error for non-admin user compatible with Drupal 8.6
Comment #15
grndlvl CreditAttribution: grndlvl at GollyGood Software for Zivtech commentedRe-roll for 8.6.x & 8.7.x.
Comment #16
kalyansamanta CreditAttribution: kalyansamanta at Asentech LLC commentedPlease check this one.
Comment #17
cilefen CreditAttribution: cilefen as a volunteer commentedComment #18
grndlvl CreditAttribution: grndlvl at GollyGood Software for Zivtech commentedI would say that the cache context is still needed. Un-hiding #15 for this.
Comment #20
geek-merlinI'd propose to fold this issue into #2906919: Allow users to create a block content entity with a specific UUID if it is a missing dependency of a config object.
Comment #21
PanchoWe don’t want ordinary users to create block content. So the two issues are complementary.
Comment #24
LaravZ CreditAttribution: LaravZ as a volunteer and at Ordina Digital Services for DICTU commentedThe solutions that include 'trigger_error' still trigger a user error for anonymous users on my local installations (unless I completely hide all messages from anonymous users). For now #14 seems to be a valid solution where the message is hidden for anonymous users based on a permission.
Comment #25
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedComment #26
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commented#14 looks good to me. I agree to the fact that if trigger_error would be suppressed on production it need not be included in the patch. Rectifying line ending in the patch #14 so that Drupal ci test cases pass. This patch works with Drupal 9.1.x
Comment #27
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedAttaching the interdiff file (patch in #26 and #16) in this comment.
Comment #28
paulocsPatch #27 looks good to me.
Admin user:
Anonymus user:
Authenticated user:
Comment #29
tim.plunkett'user.permissions'
is already a required cache contextComment #30
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedHi @timplunkett,
This patch contains the Functional Test for broken block visibility as well.
As per your comment:
the class Broken no longer extends BlockBase in version 9.1
Please let me know for any other required change.
Comment #31
tim.plunkettI don't understand what the Broken/BlockBase change has to do with the fact that
user.permissions
is in required_cache_contexts: https://git.drupalcode.org/project/drupal/-/blob/9.0.x/core/core.service...Also, please include an interdiff when making changes to a patch. Thanks!
Comment #32
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedHi @timplunkett,
Here is the patch with changes as discussed.
Changes are :
1. Removal of user.role cache context
2. Added User permission check v.i.a dependency injection
3. Functional Test for Broken Block Visibility
Have generated an interdiff between 26 and 32 so that it shows all the changes.
Comment #33
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedComment #35
harpreet16 CreditAttribution: harpreet16 at Srijan | A Material+ Company for Drupal India Association commentedUploading a test patch to for Drupal CI test results that includes:
1. Removal of user.role cache context
2. Added User permission check v.i.a dependency injection
3. Functional Test for Broken Block Visibility
4. Changes in BlockManagerTest to use AccountProxyInterface object.
Comment #36
raman.b CreditAttribution: raman.b at OpenSense Labs commentedNot sure if it's the best way to fix the broken test, but would like to move this issue forward
Comment #37
raman.b CreditAttribution: raman.b at OpenSense Labs commentedComment #39
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedI have applied the above patch on 9.2.x dev version ,the patch works fine
Before patch
After patch .RTBC
Comment #40
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedComment #41
tim.plunkettI went to go fix the usage of getMockBuilder and noticed that AccountProxyInterface was being used instead of AccountInterface.
No need for more manual testing as this doesn't affect the fix, but a review of my test changes is welcome.
Comment #42
paulocsThe test changes look goods to me.
Thanks tim.plunkett
Moving to RTBC.
Comment #43
alexpottCommitted 8e416f1 and pushed to 9.2.x. Thanks!
I'll discuss backporting once the 9.1.0 alpha is out with the release managers.
Comment #45
alexpottCherry-picked to 9.1.x
Comment #48
SpokjeIn #3160629: BlockPluginTrait cannot call ::addContextAssignmentElement() itself which we want to backport to D8.9.x, we found out that the testing of this issue piggybacks on the test introduced in this issue (
\Drupal\Tests\block\Functional\BlockUiTest::testBrokenBlockVisibility
)https://www.drupal.org/project/drupal/issues/3160629#comment-14048432
and
https://www.drupal.org/project/drupal/issues/3160629#comment-14048448
Therefore we like to backport this issue as well.
Since this issue is already
Closed (fixed)
I can't reopen it. Is there somebody around with the almighty powers to do so?Comment #49
tim.plunkettReopening because I can, but I'm not sure above backporting this just because the other issue needs it. Not against that per se, I defer to the framework and release managers.
Comment #50
SpokjeThanks @tim.plunkett for re-opening.
Tagged accordingly.
Comment #51
longwaveRerolled #41 against 8.9.x. The layout builder parts of #41 don't exist in 8.9.x and aren't needed here, otherwise this applies cleanly.
Comment #52
SpokjeOpened an issue about branch
8.9.x
not passing the tests any more: #3206826: Branch 8.9.x doesn't pass tests anymoreComment #53
quietone CreditAttribution: quietone as a volunteer commentedSince Bugfix support for Drupal 8.9.x is restricted to selected low-disruption major and critical bug-fixes and this was committed to Drupal 9, changing status to Fixed.