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

Nedjo Rogers nedjo at islandnet.com
Wed Jul 5 23:13:01 UTC 2006


>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