Sorry for the newbie questin but Im new to druapl and to php but Im having the toughest time trying to figure out where to add the code to make the blocks multiblock enabled. Can you please give me more guidance as to what file or files need to be modified

Comments

ocarina’s picture

The readme file included with the module explains how to do it. But here's how and some very basic example code:

Implement hook_block.

Add an if statement to handle the op 'mb_enabled':

if ($op == 'mb_enabled') {
  return 'mb_enabled';
}
else if ($op == 'list') {
  // etc...
}

When $op is 'view', 'configure', or 'save' use the multibox delta in $edit to effect the right block instance.

if ($op == 'view') {
  $instance = $edit['multiblock_delta']['#value'];
  // $delta is the block type number that the normal hook_block uses.
  $data = variable_get('mymodule_block'.$delta.'_'.$instance, null);
  // change $data however you want here
  $block = array('subject' => 'Subject', 'content' => $data)
}

Now that your hook_block is multiblock ready you can start cloning it on the admin/build/block/instances page.

When I tried multiblock myself it wasn't saving different settings for each block. I found some bug fixing patches for multiblock that aren't part of the download on the main page yet. Replacing multiblock_add_form_submit (in multiblock.module) with this seems to fix the problem if you ever have it:

function multiblock_add_form_submit($form, &$form_state) {
  // Get the original block info.
  $orig_block = multiblock_blockinfo_from_form($form_state['values']['block']);
  // Create block instance information.
  $orig_block = (object) $orig_block;
  // Check whether this module is multiblock enabled.
  $mb_enabled = (int) (module_invoke($orig_block->module, 'block', 'mb_enabled') == 'mb_enabled');
  $instance = (object) array('title' => $form_state['values']['title'], 'mb_enabled' => $mb_enabled);
  // Add the block instance.
  multiblock_add($orig_block, $instance);
  drupal_set_message(t('Block instance %instance created.', array('%instance' => $form_state['values']['title'])));
}
andrewlevine’s picture

Status: Active » Fixed

Thanks for taking the time to explain this ocarina, I really appreciate it.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

moosedog’s picture

where do you add the if statement?

knalstaaf’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Where do we have to "implement hook_block"? In the template.php?

intrafusion’s picture

Status: Active » Closed (works as designed)

In a custom module