Andrew: We have spoken over email and I wanted to bring this feature request up in a ticket.

I have a need for the multiblock to contain arguments in key=value pairs. I have a few blocks that will be used as multiblock instances. Each of these instances should have an argument set. This set is not going to be available via the URL - as there will be multiple instances per page - each with their own unique argument value set.

Using the "mb_enabled" feature currently available in the module I can achieve what I need, but I'm forced to do it programmatically. I need a way for a site editor (who is not a PHP programmer and will have no access to the raw module files) to be able to specify additional parameters via the form on instance creation. I'm not sure how this can be achieved with the block_id you get back using mb_enabled without going into the block instance .module file and re-writing code. There needs to exist some way to have block_id n map to block instance argument set (k=>v,k=>v).

I have been tinkering with the module and found a way to achieve this. It's somewhat half-baked, but I'd like to share what I've done:

1: Created a new table to hold instance arguments: multiblock_args:

+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| argument_id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment | 
| multiblock_delta | int(11)          | NO   |     | NULL    |                | 
| argument_key     | varchar(64)      | YES  |     | NULL    |                | 
| argument_value   | varchar(255)     | NO   |     | NULL    |                | 
+------------------+------------------+------+-----+---------+----------------+

2: I added an argument field to the hook_add_form (this would need a major overhaul if this feature was to coalesce. I am imagining a set of three to five already available key to value textfields, with the ability for a content administrator to add more on the fly. For my testing purposes, this worked:

  $form['args'] = array(
    '#type' => 'textfield',
    '#title' => t('Arguments. key=value,key=value'),
    '#required' => FALSE,
    '#default_value' => ($update ? $update->args : NULL),
  );

3: Added this code to hook_add for argument persistence:

  if ($block_instance->args) {
    $argsArray = split(',', $block_instance->args);
    foreach ($argsArray as $arg) {
      $argParts = split('=', $arg);
      db_query("INSERT INTO {multiblock_args} (multiblock_delta, argument_key, argument_value) VALUES (%d, '%s', '%s')", $last_insert_id, $argParts[0], $argParts[1]);
    }
  }

forgive the nasty split code - that's what I would refactor out from option 2

4: Added the args to the block instance object in multiblock_add_form_submit:

  $instance = (object) array('title' => $form_state['values']['title'], 'mb_enabled' => $mb_enabled, 'args' => $form_state['values']['args']);

I haven't done any code changes on the update and delete logic, as this is somewhat of a proof of concept right now. I have attached a zip containing for the .install and the .module I was tinkering with.

Hope I can help more with this

CommentFileSizeAuthor
multiblock_args_proofofconcept.zip4.93 KBrcurts
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrewlevine’s picture

Hey, I was waiting for an answer to your email to respond but maybe it got buried in your inbox.

Anyway, the problem I have with this is that it's a little like re-implementing CCK inside of multiblock. Ideally, we would want "argument" values of all types, not just varchar(255). I think Node Blocks is perfect for this. Any ideas for how we could integrate multiblock and node blocks?

NancyDru’s picture

I am interested in this as well because I think it would be a big help with Panels.

intrafusion’s picture

Status: Active » Closed (works as designed)