5

Is there a way to determine a block's module given only the block's delta? I'm hoping for a solution that does not require a custom query.

Use case:
We are enabling our client to decide which blocks are displayed on a given content type. Those options include blocks created through the block admin interface and blocks created through the views admin. From what I can tell, a regular block and a view's block are rendered differently so psuedo code would be something like.

// In preprocessing
if($block_module === 'views') {
    // do view rendering
} else {
    // do normal block rendering
}

Any ideas?

  • This doesn't exactly answer but might be useful depending on your use case: have you considered Entity Views Attachments (EVA)? – beth Feb 17 '13 at 18:45
  • Are you trying to theme a block differently depending on what module created it? If so, you can use the template system to achieve that. (E.g. block--[module-1].tpl.php and block--[module-2].tpl.php) – Adam Balsam Feb 17 '13 at 19:18
  • also you can handle it in theme level, for example block--views.tpl.php and block.tpl.php can render differently. – Mohammad Ali Akbari Feb 17 '13 at 19:57
0

No, it's not possible without having the module name.

Block deltas only need to be unique per module, so any two modules could implement a block with exactly the same delta, and you'd have no way to determine which was which without the module name.

The simplest proof of this in the code is the block_load() function, which has this signature:

function block_load($module, $delta) {

As you can see, even Drupal can't load the details of a block without knowing the module name unfortunately.

  • 1
    Thanks Clive. In the end I did the following, which works well in my situation. Essentially, get a list of the blocks in the views module $blocks = module_invoke('views', 'block_info'); and iterate through those to see if the delta exists. If it does, I know I have a views block, if not I know it's a regular block. – David Feb 18 '13 at 22:18

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.