7.x block.api.php hook_block_view_MODULE_DELTA_alter(&$data, $block)

Perform alterations to a specific block.

Modules can implement hook_block_view_MODULE_DELTA_alter() to modify a specific block, rather than implementing hook_block_view_alter().


$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 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



Related topics

3 string references to 'hook_block_view_MODULE_DELTA_alter'
2 functions implement hook_block_view_MODULE_DELTA_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

block_test_block_view_block_test_test_hyphen_alter in modules/block/tests/block_test.module
Implements hook_block_view_MODULE_DELTA_alter().
block_test_block_view_block_test_test_underscore_alter in modules/block/tests/block_test.module
Implements hook_block_view_MODULE_DELTA_alter().


modules/block/block.api.php, line 309
Hooks provided by the Block module.


function hook_block_view_MODULE_DELTA_alter(&$data, $block) {

  // This code will only run for a specific block. For example, if MODULE_DELTA
  // in the function definition above is set to "mymodule_somedelta", the code
  // will only run on the "somedelta" block provided by the "mymodule" module.
  // Change the title of the "somedelta" block provided by the "mymodule"
  // module.
  $data['subject'] = t('New title of the block');


Niklas Fiekas’s picture

Is it possible to use this hook with deltas, that wouldn't make a valid function name?
Like hook_block_view_system_user-menu_alter()?

adaddinsane’s picture

Just ran into this myself. I've reported the issue and provided a solution here http://drupal.org/node/1076132 . The fix is in block.module, not menu.module.

selltrends’s picture

I tried, hook_block_view_system_user-menu_alter() can not work. But switch the hook_block_view_alter() can work, for example:
function hook_block_view_alter(&$data, $block) {

if ($block->delta == 'user-menu') {
$data['content'] = 'XXX';

ronm’s picture

Name your function hook_block_view_system_user_menu_alter note the underscore between "user" and "menu", this should work!

mshepherd’s picture

Once off the front page I needed the page title to be rendered as the block title for the main content block. This worked a treat:

function MYMODULE_block_view_system_main_alter(&$data, $block) {
  if (!drupal_is_front_page()) {
    $data['subject'] = drupal_get_title();
hmartens@gmail.com’s picture

Thanks for this. I'm using module Menu Block and I need the block's title to be set to the page title.

Can the MYMODULE be any name or is it specific to something?

hwi2’s picture

Yes, interestingly, this worked well where I could not get hook_block_view_MODULE_DELTA_alter to work at all. I did what you said and used hook_block_view_alter with $block->delta and that did the trick.

bjones1983’s picture

How could I use this hook to tell specific block to only show(visible) when specific content(like Blog) is used to create node by user.