Argument Passing

NoCoolNamesRemain - August 31, 2009 - 17:03
Project:Insert Block
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I would like to be able to pass arguments to the block being called. It seems similar functionality is built into the Insert Views module and it also seems to be supported by module_invoke(). The biggest challenge for me would be correctly modifying the regex used by this module (_insert_block_substitute_tags()).

#1

NoCoolNamesRemain - September 1, 2009 - 21:53

Here is what I have come up with (which is working for me). I would like someone to verify that the regular expresion does ONLY what I want.

function _insert_block_substitute_tags($text) {
  if (preg_match_all("/\[block:([^=\\]]+)=?([^=\\]]*)? args:?([^\\]]*)?\]/i", $text, $match)) {

    foreach ($match[3] as $key => $value) {
      $raw_tags[] = $match[0][$key];
      $module = $match[1][$key];
      $delta = $match[2][$key];
      $args = $match[3][$key];

      if ($args != NULL) {
        $args = explode(',', $args);
      }
      else {
        $args = array();
      }

      $block = module_invoke($module, 'block', 'view', $delta, $args);

      $repl[] = theme('insert_block_block', $block);
    }
    return str_replace($raw_tags, $repl, $text);
    //return print_r($match); //TESTING
  }
  return $text;
}

[block:MODULE=DELTA args:ARG1,ARG2,...,ARGN]

 
 

Drupal is a registered trademark of Dries Buytaert.