Making blocks multiblock enabled

rmarmon - July 21, 2008 - 00:43
Project:MultiBlock
Version:6.x-1.1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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

#1

ocarina - September 8, 2008 - 01:17

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'])));
}

#2

andrewlevine - September 24, 2008 - 03:43
Status:active» fixed

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

#3

Anonymous (not verified) - October 8, 2008 - 03:52
Status:fixed» closed

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

#4

moosedog - October 30, 2008 - 03:53

where do you add the if statement?

 
 

Drupal is a registered trademark of Dries Buytaert.