[development] hook_block can set properties (weight, enabled, etc.) for blocks

Gabor Hojtsy gabor at hojtsy.hu
Wed Jul 5 08:36:12 UTC 2006


Could you please document it on hook_block() in contrib? Just today I 
showed the hook block to some, and they stumbled on the need to pass an 
array of arrays with the 'list' op. I said there can be more keys 
additionaly to info. But these are not documented at hook_block().

Gabor

On Wed, 5 Jul 2006, Nedjo Rogers wrote:

>> A quick FYI for module authors. As of 4.7, we can set all block properties 
>> except theme in hook_block (instead of, previously, just 'content' and 
>> 'subject'). This is a change that was part of the block region patch. So, 
>> for example, you can give your blocks an explicit weight, enable them, 
>> limit them to given pages, etc. Example:
>> 
>> $block = array('weight' => -6, 'enabled' => 1, 'region' => 'content', 
>> 'subject' => t('Example'));
>> $block['content'] = t('This is an example');
>
> A correction. We can indeed assign blocks initial values in hook_block(), but 
> we do so in the 'list' op, not the 'view' one. So, instead of what I wrote 
> above, use something like:
>
> /**
> * Implementation of hook_block().
> */
> function example_block($op = 'list', $delta = 0) {
> global $user;
> if ($op == 'list') {
> $blocks[0] = array(
> 'info' => t('Example'),
> 'status' => 1
>> ;
>  return $blocks;
> }
> ...
> } 
>


More information about the development mailing list