Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If I want a block exactly the same except for a minor change, it would be nice to have a hook before display where I can change the contents of the block.
Comment | File | Size | Author |
---|---|---|---|
#7 | 366788.patch | 2.24 KB | andrewlevine |
#2 | multiblock.alter6_.patch | 946 bytes | NancyDru |
Comments
Comment #1
NancyDruI assume this would be after op='view' is done. Hmm, I wonder why there is no
hook_block_alter
? Would that be a good name for this?Comment #2
NancyDruSomething like the attached? There is a working hook_block_alter at the bottom of the patch, which will be deleted before committing.
BTW, I did test changing
$block['content']
and it worked.Comment #3
andrewlevine CreditAttribution: andrewlevine commentedNancy, exactly what I was thinking. Although now that I see it in code, I don't see any reason why this shouldn't apply for every op (not just view). I imagine this would be very useful for modules that aren't multiblock enabled, but you want to change how the block (or how a specific instance of a block) functions without hacking it. This could be a new use for multiblock: slightly modifying the functionality of particular block instances (boxes) without hacking the module.
Also I guess I would name it hook_multiblock_alter because it will not work with all blocks. I will draw up a patch soon.
P.S. Thanks so much for writing up this patch. I know how busy you are so I hope you don't feel obligated to respond to all my little issues. I appreciate your help but I don't want you to burn out!
Andrew
Comment #4
NancyDruI thought it would be an interesting exercise and I needed a break from doing my other issues. I'm interested in seeing you extending this to the other ops and particularly to how they might be used. Doing op=configure might make multiblock-enabling and interesting exercise. I wonder if there could be some way to save instance-specific settings that would be passed to the underlying block?
Comment #5
andrewlevine CreditAttribution: andrewlevine commentedHmm...I have a feeling multiblock-enabling with this hook might be tough because data is queried and displayed inside the configure hook rather then queried in a pre-configure hook and displayed in the configure hook. But I'll take an in depth look once I write the patch.
Comment #6
NancyDruI wonder if some sort of "pre-configure" op could be used. The module would say "these are the fields I need" and Multiblock could keep a set of those values per instance. Wow, I'd never have to write another multiblock implementation again...
Comment #7
andrewlevine CreditAttribution: andrewlevine commentedHere's my go at the patch.
I couldn't think of any way to do what you were requesting in #6 because code in the 'save' op in hook_block is too varied between modules to know what to pass in with configure. Although with this patch you will be able to perform your own actions after the original module's save fires which might help.
Comment #8
intrafusionIssue closed as last post 6 years ago