Add original block module and delta on view

quicksketch - June 3, 2008 - 20:50
Project:MultiBlock
Version:5.x-1.0
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

On block view, it would be handy to have the original block delta and module in the new multiblock instance, so that the newly created instance could have a class that displays the original block and delta for styling.

AttachmentSize
multiblock_orig.patch776 bytes

#1

jjeff - June 3, 2008 - 21:10

Actually, that patch had some major problems. Here's an updated version that actually works. :-)

AttachmentSize
multiblock-orig-classes.patch 1.31 KB

#2

quicksketch - June 4, 2008 - 06:18

For the D5 version the original patch is going to be as good as we can do, we don't get preprocess hooks in D5 :(

Though noted, the block seems to be an array, not an object at that point.

#3

andrewlevine - June 8, 2008 - 02:47

quicksketch et al., if this information is useful in the view op, is there any reason we shouldn't include it in all the other ops?

#4

quicksketch - June 24, 2008 - 00:08

As jjeff informed me, the block object isn't always an object (or array, whatever) during all operations. Though I agree that it would probably be helpful in more operations than just view.

#5

andrewlevine - July 15, 2008 - 16:52

quicksketch, now that I think about it, I made the whole multiblock_enabled thing to give you the delta of the block. Couldn't you use that to get the same info?

#6

andrewlevine - December 7, 2008 - 06:12
Status:needs review» postponed (maintainer needs more info)

#7

NancyDru - January 4, 2009 - 04:49

Something I thought as I was trying to understand this is that some people have their CSS set up for specific blocks as natively generated. It might be more of a point to somehow tell the theme layer that the original module created the block rather than MB, perhaps with the addition of the instance ID.

#8

NancyDru - January 4, 2009 - 04:50

To some extent #346513: block-{region}.tpl.php not used is part of this discussion as well.

#9

NancyDru - January 6, 2009 - 19:09

I've been trying something similar to jjeff's patch. In function multiblock_call_block, I did:

    $block = module_invoke($block_info->module, 'block', $op, $block_info->orig_delta, $edit);
    if ($op == 'view') {
      $block['orig_module'] = $block_info->module;
      $block['orig_delta'] = $block_info->orig_delta;
    }
    return $block;

And then I modified block.tpl.php like this:

<?php
// $Id: block.tpl.php,v 1.3 2007/08/07 08:39:36 goba Exp $
 
global $user;
 
$classes = 'clear-block block block-'. $block->module;
  if (!empty(
$block->orig_module)) {
   
$classes .= ' block-'. $block->orig_module;
   
$classes .= ' block-'. $block->orig_module .'-'. $block->orig_delta;
  }
?>

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="<?php print $classes ?>">

<?php if (!empty($block->subject)): ?>
  <h2><?php print $block->module == 'user' ? theme('username', $user) : $block->subject ?></h2>
<?php endif;?>

  <div class="content"><?php print $block->content ?></div>
</div>

This passes the original module and delta to the template, which then adds what would have been the original ID as a class (can't nest div's because you could then have duplicate IDs which would fail validation).

This should work in both 5.x and 6.x. The downside is that 5.x users would have to copy the template to their theme directory, which means it's out of our ability to maintain it. However, I think that is a small risk.

 
 

Drupal is a registered trademark of Dries Buytaert.