Hello! I am running on Drupal 7 with Context 7.x-3.0-beta6 and I noticed that a block code is being executed even if I have disbled the whole region in my theme.

I tried this using a custom block with the following code: drupal_set_message('Hello There');
and I noticed that the message appears in every page, even if the Region has been disabled with context module

Comments

eanushan’s picture

I can confirm this bug exists in 7.22 as well in a slightly different case. If I set a block to only be visible to certain role types, the code in the block is executed for all roles, but the output is simply hidden for the roles that are not checked. This has some strange side effects like the one mentioned by the bug reporter as well as performance implications if there is a particularly bulky module that should only be visible to administrators for example.

This happens in Drupal core though, so maybe we should move the ticket over there.

eanushan’s picture

Project: Context » Drupal core
Version: 7.x-3.0-beta6 » 7.22
Component: Code » block.module
Priority: Critical » Normal
David_Rothstein’s picture

Project: Drupal core » Context
Version: 7.22 » 7.x-3.0-beta6
Component: block.module » Code

I wasn't able to reproduce this with Drupal core alone, and don't see how it could be? (The code to hide blocks that are not supposed to be visible happens in block_block_list_alter() which is invoked by _block_load_blocks() right after the blocks are loaded from the database, and therefore well before they are rendered.)

If anyone can find reproducible steps to hit this problem with Drupal core alone, feel free to move it back though.

eanushan’s picture

Ah, it seems the reason this is occuring is because the block in question was implementing hook_node_view. Even if the block is not visible, the hook will be executed. I think this is as expected, so indeed, it is not a Drupal core bug.

eanushan’s picture

Status: Active » Closed (works as designed)
mavrom’s picture

Version: 7.x-3.0-beta6 » 7.x-3.0-beta7

Hi EAnushan,

Here is a very simple way to reproduce the bug:

Use Drupal 7.23, latest context module version, and devel

1) Create a simple block using Drupal UI with the following body (set filter to PHP code)

Hello There!!!
<?php
dpm('Hello There!!!');
?>

2) Use the bartik theme and place the block to second sidebar (every where in drupal I expect to see the block and the dpm message)
3) Use the context module and
-Action: a particular path (i.e node/6)
-Reaction: Disable Region second sidebar

You will notice, that although the block is not shown, the dpm message still appears in path node/6.
I wouldn't expect to see the dpm message

mavrom’s picture

Status: Closed (works as designed) » Active

I set the status to active, since I think this worth to check

artem_sylchuk’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new937 bytes

Faced the same issue. Wouldn't this help?

Status: Needs review » Needs work
artem_sylchuk’s picture

Status: Needs work » Needs review
loze’s picture

StatusFileSize
new2.13 KB

This was my attempt at fixing this
I've been using this patch for a while now in production. It seems to do the trick.

loze’s picture

Version: 7.x-3.0-beta7 » 7.x-3.x-dev
bzoks’s picture

Status: Needs review » Reviewed & tested by the community

I tested both patches and by using test procedure from post #6 patch from #8 works correctly, and patch under #11 does not.
I, therefore, suggest accepting patch #8.

loze’s picture

This is happening on the D8 version as well.

To reproduce:

  • create a block that adds a status message
  • add the block to a context
  • disable the region that you just placed the block
  • visit a page that triggers the context
  • the status message is displayed.

Not sure if I should create a separate issue for this.

loze’s picture

Sorry, I was mistaken. Ignore my last comment.