1 layout.api.php hook_block_view_alter(&$data, $block)

Perform alterations to the content of a block.

This hook allows you to modify blocks before they are rendered.

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.


$data: The block title and content as returned by the module that defined the block. This could be an empty array or NULL value (if the block is empty) or an array containing the following:

  • title: The (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. It will have have at least the following 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().
  • settings: An array containing all block settings as defined for this instance of the block.
  • contexts: An array containing all layout contexts available for the layout.

See also



Related topics


core/modules/layout/layout.api.php, line 697
Describe hooks provided by the Layout module.


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'])) {
  // Add a theme wrapper function defined by the current module to all blocks
  // provided by the "some_module" module.
  if (is_array($data['content']) && $block->module == 'some_module') {
    $data['content']['#theme_wrappers'][] = 'my_module_special_block';