0

I have a new text format sample_page with the filter sample_page, I've created using hook_filter_info(). In the callback, I am rendering a webform using depending on the token in the node body, for webform I'm planning to use a token [block:webform:webform-client-form-2423].

I could render the blocks created programmatically, system blocks. But not the blocks created by other modules, I have tried [block:user:login] from http://mine.local/admin/structure/block/manage/user/login/configure to render to login blocks too. But these blocks didnt seems to work. Here is my callback for filter.

System blocks that worked for me, I used the token [block:block:25] from http://mine.local/admin/structure/block/manage/block/2/configure and for blocks created programatically by my own module, suppose my module is my_module, I have used the token [block:my_module:block_name] from the url http://mine.local/admin/structure/block/manage/my_module/block_name/configure

preg_match_all('/\\[([a-zA-z0-9_\-]+:[a-zA-z0-9_\-]+)+\\]/m', $text, $match);
$matches = $match[0];
foreach ($matches as $token) {
  $token_name = str_replace(array( '[', ']' ), '', $token);
  $type = explode(':', $token_name);
  if ($type[0] == 'block') {
    $module = $type[1];
    $bid = $type[2];
    $block = block_load($module, $bid);
    $replacement = render(_block_get_renderable_array(_block_render_blocks(array($block)))); 
  }
}

Can any one look into the problem. Any help would be appreciated...

1

You can add the webform using hook_page_alter().

/**
 * Implements hook_page_alter().
 */
function my_module_page_alter(&$page){

  // Get the webform's nid that you want to display on the current page.
  $webform_nid = my_module_webform_to_display();

  // Load the webform node.
  $webform = node_load($webform_nid);

  // Render the webform using my custom view mode.
  $markup = drupal_render(node_view($webform, 'my_custom_view_mode'));

  // Add the markup to the page element.
  $page['content']['system_main'][] = array(
    '#markup' => $markup,
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.