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

CommentFileSizeAuthor
#51 2918149-50-8.9.x.patch5.25 KBlongwave
#41 2918149-brokenblock-41-interdiff.txt6.8 KBtim.plunkett
#41 2918149-brokenblock-41.patch7.09 KBtim.plunkett
#39 before__patch.jpg269.89 KBranjith_kumar_k_u
#39 after__patch.jpg226.57 KBranjith_kumar_k_u
#36 interdiff_35-36.txt1.41 KBraman.b
#36 2918149-36.patch7.96 KBraman.b
#35 interdiff_32-35.txt1.75 KBharpreet16
#35 2918149-35.patch6.13 KBharpreet16
#32 interdiff__26-32.txt4.92 KBharpreet16
#32 2918149--32.patch4.85 KBharpreet16
#30 2918149-30.patch3.2 KBharpreet16
#28 Authenticated user.png16.23 KBpaulocs
#28 anonymous user.png11.87 KBpaulocs
#28 admin user.png44.41 KBpaulocs
#27 interdiff.txt1.28 KBharpreet16
#26 2918149-26.patch636 bytesharpreet16
#16 this_block_is_broken_or_missing-2918149-16.patch774 byteskalyansamanta
#15 2918149-15.patch810 bytesgrndlvl
#14 2918149-this-block-broken-or-missing-14.patch624 bytesnikunjkotecha
#10 interdiff.txt1.29 KBanil.gangwal
#10 2918149-this-block-broken-or-missing-10.patch1.45 KBanil.gangwal
#4 2918149-this-block-broken-or-missing-4.patch1.25 KBdalin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dalin created an issue. See original summary.

tim.plunkett’s picture

Issue tags: -Blocks-Layouts

Another 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.

manuel.adan’s picture

In 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.

dalin’s picture

Status: Active » Needs review
FileSize
1.25 KB

Another idea would be to use trigger_error instead, which can be suppressed on production.

But that's why we can't use trigger_error exclusively, we'll want content editors to see the message.

First patch attempt.

Status: Needs review » Needs work

The last submitted patch, 4: 2918149-this-block-broken-or-missing-4.patch, failed testing. View results

dalin’s picture

All those tests intentionally create broken blocks??? That can't be right.

tim.plunkett’s picture

Yes, 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.

froboy’s picture

I'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?

dalin’s picture

Do we need to deal with the test issue to call this RTBC

Yup. We can't commit broken tests.

anil.gangwal’s picture

Simplified 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.

dalin’s picture

@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.

As both error message should not trigger simultaneously

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:

  • to show a message to an administrator (since errors are probably hidden from screen on production sites)
  • to guarantee that the block has some content (to guarantee that it will be rendered, including contextual links, or whatever additional affordances are provided by Panels (or other layout systems)

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nikunjkotecha’s picture

Simple patch to avoid showing error for non-admin user compatible with Drupal 8.6

kalyansamanta’s picture

cilefen’s picture

Status: Needs work » Needs review
grndlvl’s picture

I would say that the cache context is still needed. Un-hiding #15 for this.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Pancho’s picture

We don’t want ordinary users to create block content. So the two issues are complementary.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

LaravZ’s picture

The 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.

harpreet16’s picture

Assigned: Unassigned » harpreet16
harpreet16’s picture

#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

harpreet16’s picture

Assigned: harpreet16 » Unassigned
FileSize
1.28 KB

Attaching the interdiff file (patch in #26 and #16) in this comment.

paulocs’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
44.41 KB
11.87 KB
16.23 KB

Patch #27 looks good to me.

Admin user:

Admin User

Anonymus user:

Anonymus User

Authenticated user:

Authenticated User

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
  1. Before it can be committed, it needs automated test coverage.
  2. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
    @@ -20,7 +20,12 @@ class Broken extends BlockBase {
    +    $build['#cache']['contexts'] = ['user.roles'];
    

    'user.permissions' is already a required cache context

harpreet16’s picture

Hi @timplunkett,
This patch contains the Functional Test for broken block visibility as well.

As per your comment:

user.permissions' is already a required cache context

the class Broken no longer extends BlockBase in version 9.1
Please let me know for any other required change.

tim.plunkett’s picture

I don't understand what the Broken/BlockBase change has to do with the fact that

  1. The code doesn't check user roles, it checks user permissions
  2. 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!

harpreet16’s picture

FileSize
4.85 KB
4.92 KB

Hi @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.

harpreet16’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 32: 2918149--32.patch, failed testing. View results

harpreet16’s picture

FileSize
6.13 KB
1.75 KB

Uploading 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.

raman.b’s picture

Status: Needs work » Needs review
FileSize
7.96 KB
1.41 KB

Not sure if it's the best way to fix the broken test, but would like to move this issue forward

raman.b’s picture

Issue tags: -Needs tests

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ranjith_kumar_k_u’s picture

FileSize
226.57 KB
269.89 KB

I have applied the above patch on 9.2.x dev version ,the patch works fine
Before patch before patch
After patch after patch.RTBC

ranjith_kumar_k_u’s picture

Status: Needs review » Reviewed & tested by the community
tim.plunkett’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
FileSize
7.09 KB
6.8 KB

I 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.

paulocs’s picture

Status: Needs review » Reviewed & tested by the community

The test changes look goods to me.
Thanks tim.plunkett

Moving to RTBC.

alexpott’s picture

Title: "This block is broken or missing..." should only be shown to users that have access to do something about it » [backport] "This block is broken or missing..." should only be shown to users that have access to do something about it
Version: 9.2.x-dev » 9.1.x-dev

Committed 8e416f1 and pushed to 9.2.x. Thanks!

I'll discuss backporting once the 9.1.0 alpha is out with the release managers.

  • alexpott committed 8e416f1 on 9.2.x
    Issue #2918149 by harpreet16, tim.plunkett, raman.b, anil.gangwal, dalin...
alexpott’s picture

Title: [backport] "This block is broken or missing..." should only be shown to users that have access to do something about it » "This block is broken or missing..." should only be shown to users that have access to do something about it
Status: Reviewed & tested by the community » Fixed

Cherry-picked to 9.1.x

  • alexpott committed 079d104 on 9.1.x
    Issue #2918149 by harpreet16, tim.plunkett, raman.b, anil.gangwal, dalin...

Status: Fixed » Closed (fixed)

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

Spokje’s picture

In #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?

tim.plunkett’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Closed (fixed) » Patch (to be ported)

Reopening 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.

Spokje’s picture

Thanks @tim.plunkett for re-opening.

I defer to the framework and release managers.

Tagged accordingly.

longwave’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.25 KB

Rerolled #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.

Spokje’s picture

Opened an issue about branch 8.9.x not passing the tests any more: #3206826: Branch 8.9.x doesn't pass tests anymore

quietone’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Fixed
Issue tags: +Bug Smash Initiative

Since 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.

Status: Fixed » Closed (fixed)

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