2

I have a created a block using UI .I want to change the content of the block programmatically. For this I am using hook_block_view_alter(&$data, $block) for it as follows: I have just created a block using UI and I am going to assign certain pages which will be able to see that view..

function hook_block_view_alter(&$data, $block) {
if ($block->delta == 'HOW CAN I GET THE $DELTA here') {
$data['#markup'] = '<a href="www.google.com">Google</a>';

} 

}
  • Is it a custom or module-provided block? If module, which module? – Clive Nov 13 '13 at 16:19
  • I have just created a block using UI and I am going to assign certain pages which will be able to see that view.. – harshal Nov 13 '13 at 16:27
  • 1
    Why not create the block also in code? – Елин Й. Nov 13 '13 at 16:29
  • yes I want to codify the block any ideas? – harshal Nov 13 '13 at 16:30
  • 1
    @ЕлинЙ. That's the real question ;) The delta for custom blocks is the block ID (check the URL when you edit the block), you'll also want to check that $block->module == 'block' so you don't get collisions with other modules. But really, implementing hook_block_info() and hook_block_view() yourself would be a much more reusable solution – Clive Nov 13 '13 at 16:30
5

If you go to admin/structure/block and mouseover the "configure" link you'll see something like this for blocks added through UI:

/admin/structure/block/manage/block/1/configure

something like this for blocks created with views:

/admin/structure/block/manage/views/81e6b321879efa58ba9e546521c14467/configure

something like this for blocks created with webform:

/admin/structure/block/manage/webform/client-block-50/configure

something like this for blocks created by the system (core):

/admin/structure/block/manage/system/main/configure

I've bolded the deltas and italicized the modules in each example.

  • 3
    Don't forget different modules can define the same delta, so it's important to check $block->module as well as the delta or you might end up addressing the wrong one – Clive Nov 13 '13 at 16:59
  • good point Clive – Scott Joudry Nov 13 '13 at 17:20
2

Find the block on the Blocks configuration page, and click the "configure" link.

Look at the URL. The URL path tells you both the module that is responsible for the block, and the delta assigned to it. Here's the URL pattern:

/admin/structure/block/manage/ MODULENAME / DELTA /configure

So if your URL path is "/admin/structure/block/manage/block/5/configure", then that particular block is maintained by the "block" module, and the delta for the block is "5".

  • Scott beat me by 2 minutes! – Les Lim Nov 13 '13 at 16:57
1

You can always get the delta by quering your DB (handy in cases where custom blocks are generated automatically and the delta is dynamic)

  $result = db_select('block_custom', 'b')
     ->fields('b', array('bid'))
     ->condition('info', '<ADMIN TITLE OF THE BLOCK>')
     ->execute()
     ->fetchAssoc();

  // if $result['bid'] exists..

  $delta = db_select('block', 'b')
     ->fields('b', array('delta'))
     ->condition('bid', $result['bid'])
     ->execute()
     ->fetchAssoc();

  $delta = $delta['delta'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.