hook_block can set properties (weight, enabled, etc.) for blocks
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'); These settings will be registered when the block is first loaded at admin/block, and from there can be changed manually via block administration. Note that if you set a region that isn't available in a given theme, the block will be registered instead to that theme's default region (the first item in the _regions array).
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; } ... }
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; } ... }
On 7/5/06, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
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
I've updated docs for both 4.7 and HEAD. andrew
Great, thanks. Gabor On Wed, 5 Jul 2006, andrew morton wrote:
On 7/5/06, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
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
I've updated docs for both 4.7 and HEAD.
andrew
participants (3)
-
andrew morton -
Gabor Hojtsy -
Nedjo Rogers