function hook_block_view_alter in Drupal 7
Same name and namespace in other branches
- 8 core/modules/block/block.api.php \hook_block_view_alter()
- 9 core/modules/block/block.api.php \hook_block_view_alter()
- 10 core/modules/block/block.api.php \hook_block_view_alter()
Perform alterations to the content of a block.
This hook allows you to modify any data returned by hook_block_view().
Note that instead of hook_block_view_alter(), which is called for all blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a specific block.
Parameters
$data: The data as returned from the hook_block_view() implementation of the module that defined the block. This could be an empty array or NULL value (if the block is empty) or an array containing:
- subject: The default localized title of the block.
- content: Either a string or a renderable array representing the content of the block. You should check that the content is an array before trying to modify parts of the renderable structure.
$block: The block object, as loaded from the database, having the main properties:
- module: The name of the module that defined the block.
- delta: The unique identifier for the block within that module, as defined in hook_block_info().
See also
hook_block_view_MODULE_DELTA_alter()
Related topics
1 function implements hook_block_view_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- menu_block_view_alter in modules/
menu/ menu.module - Implements hook_block_view_alter().
1 invocation of hook_block_view_alter()
- _block_render_blocks in modules/
block/ block.module - Render the content and subject for a set of blocks.
File
- modules/
block/ block.api.php, line 274 - Hooks provided by the Block module.
Code
function hook_block_view_alter(&$data, $block) {
// Remove the contextual links on all blocks that provide them.
if (is_array($data['content']) && isset($data['content']['#contextual_links'])) {
unset($data['content']['#contextual_links']);
}
// Add a theme wrapper function defined by the current module to all blocks
// provided by the "somemodule" module.
if (is_array($data['content']) && $block->module == 'somemodule') {
$data['content']['#theme_wrappers'][] = 'mymodule_special_block';
}
}