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.

CommentFileSizeAuthor
#7 366788.patch2.24 KBandrewlevine
#2 multiblock.alter6_.patch946 bytesNancyDru
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

I 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?

NancyDru’s picture

Status: Active » Needs review
FileSize
946 bytes

Something 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.

andrewlevine’s picture

Nancy, 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

NancyDru’s picture

I 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?

andrewlevine’s picture

Hmm...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.

NancyDru’s picture

I 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...

andrewlevine’s picture

FileSize
2.24 KB

Here'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.

intrafusion’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

Issue closed as last post 6 years ago