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
Comment #1
aspilicious CreditAttribution: aspilicious commentedThis is a bug it shouldn't look at the admin theme...
Comment #2
vineet.osscube CreditAttribution: vineet.osscube commentedAs 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.
Comment #3
salvisThe API description says
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.
Comment #4
drupalshrek CreditAttribution: drupalshrek commentedI have just installed 7.14 and the Devel module without changing anything and I get this error. It's annoying and disturbing.
Comment #5
dcrocks CreditAttribution: dcrocks commentedA 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?
Comment #6
drupalshrek CreditAttribution: drupalshrek commentedI did standard install.
Comment #7
dcrocks CreditAttribution: dcrocks commentedWhat 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?
Comment #8
drupalshrek CreditAttribution: drupalshrek commentedThe error didn't occur when installing 7.14, but only when I installed and enabled the 'devel' module.
Comment #9
dcrocks CreditAttribution: dcrocks commentedThis 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.
Comment #10
salvisTrying 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...
Comment #11
Rob230 CreditAttribution: Rob230 commentedIs 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.