The way DS gets the content of a block is by using:
module_invoke($module, 'block_view', $delta);
Getting the block data in this manner causes Drupal hooks (such as hook_block_view_alter()) to be bypassed.
The quick solution is get the block render array as Drupal does:
$block = block_load($module, $delta);
$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
This will result in all the appropriate hooks being fired, and allow other modules to have some control over the blocks.
There is an expressed desire to remove the block requirement from DS, which is in contradiction with this change. If #1635906: Remove 'block' module requirement for related functionality. goes through then additional checking would need to surround the above. The fallback if Block is not present could be the existing code.
An alternative to the Block module specific code could be just calling a drupal_alter() directly after the block view hook is called.
drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block);
The specific use case I am running in to is I have a module that disables blocks depending on a set context. It works just fine for any block created through core. It fails on any block that's rendered through a Display Suite field.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | ds-allow-block-hooks-to-run-1898334-0.patch | 564 bytes | steven.wichers |
Comments
Comment #1
steven.wichers commentedI can confirm that putting the following code after the
module_invoke()call will have the expected result:Comment #2
begun commentedWhere exactly are you adding the code mentioned above? I cannot find any reference to
module_invoke('block_view', $delta);in either the DS or Block modules.Comment #3
steven.wichers commentedhttp://drupalcode.org/project/ds.git/blob/refs/heads/7.x-2.x:/ds.module#...
Directly under that line. I mistyped the API call in my original post which is why you couldn't find it.
I would provide a patch, but I'm actually on DSv1 so I'm not sure if it would apply cleanly. The issue is still present in v2 which is why I posted under that branch.
Comment #4
steven.wichers commentedHere is a patch with my changes. I've been using these changes without issue for the last 2 weeks.
Comment #5
swentel commentedUploaded a patch over at #1402500: Block fields are not getting translated which completely rewrites this whole routine, now also does the drupal_alter().
Comment #5.0
swentel commentedFix mistyped API call