According to http://api.drupal.org/api/function/hook_block_info/7 I expect to be able to set


'region' => 'footer',
'status' => 1,

to have my block show up immediately in the footer region upon installation.

I have the Bartik, Garland, and Seven themes active, and apparently core tries to activate the block for every theme. It appears just fine in Bartik and Garland (NOT 'disabled'!), but Seven does not have a 'footer' region, and that's probably the reason for the error message.

This is ugly — it means that 'region' and 'status' don't really work anymore.

How to fix it? Maybe just put the message into the log but not on the screen?

Comments

aspilicious’s picture

'region': (optional) Initial value for theme region within which this block is set. Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen. Note: If you set a region that isn't available in the currently enabled theme, the block will be disabled.

This is a bug it shouldn't look at the admin theme...

vineet.osscube’s picture

As per core functionality If you set a region that isn't available in the currently enabled theme, the block will be disabled with warning message('The block [block name] was assigned to the invalid region footer and has been disabled.') and I think it is correct because if you don't show warning message on screen(module page), how will user know the cause of disabled block.

If you got any other error or warning message kindly mention it.

salvis’s picture

The API description says

Note: If you set a region that isn't available in the currently enabled theme, the block will be disabled.

It does not say there will be a warning message.

Core tries to apply the structure that you return from hook_block_info() to all active themes. I'm not sure whether Seven is enabled by default, but a lot of sites surely have it enabled, and Seven has only 'content' and 'help' regions.

In other words, if a site has Seven enabled (and all sites do), the only region you can specify with 'status'=>1 is 'content', if you don't want to bother the admin with a warning.

In yet other words, either we document that 'region'=>'content' is the only available choice, or we accept that the functionality as currently documented is broken.

drupalshrek’s picture

I have just installed 7.14 and the Devel module without changing anything and I get this error. It's annoying and disturbing.

dcrocks’s picture

A fix went in before 7.14 for issue #1172560: The block X was assigned to the invalid region Y and has been disabled.. Is this issue related to yours? What kind of install did you do?

drupalshrek’s picture

I did standard install.

dcrocks’s picture

What did you do exactly to cause the error message? I just did a 'new' standard install of 7.14 without seeing any errors, but I didn't install the 'devel' module. Did you do anything beyond installing and enabling the 'devel' module?

drupalshrek’s picture

The error didn't occur when installing 7.14, but only when I installed and enabled the 'devel' module.

dcrocks’s picture

This is a DEVEL problem to me. Quoting someone else "While assigning a block to a non-existing region is valid, having an active block assigned to an non-existing region is not", which makes sense to me. The fix in #1172560: The block X was assigned to the invalid region Y and has been disabled. does prevent the error message from repeating endlessly.

salvis’s picture

Trying to explain this a little better:

The only thing, AFAIK, a module can do to auto-enable a block when it's installed is to return the desired region and 'status' => 1 from hook_block_info().

Drupal will then try to enable the block for all themes! Since Seven only has 'content' and 'help' regions, trying to put a block into any other region (such as the 'footer', which is a very reasonable place) will cause that warning.

Devel Node Access is trying to use a documented core feature that is flawed.

If there's a better way to auto-enable a block, then let me know...

Rob230’s picture

Is there no way to programmatically set the region on a per theme basis like you can in the admin pages?

As others have said, the 'region' setting is essentially useless due to this problem. My block will work just fine with my theme, but it gets disabled on install. It should only disable it for themes that lack that region, not for all themes.