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.

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.

Members fund testing for the Drupal project. Drupal Association Learn more

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.