function _insert_block in Insert Block 7
Same name and namespace in other branches
- 8 insert_block.module \_insert_block()
- 8.x insert_block.module \_insert_block()
1 string reference to '_insert_block'
- insert_block_filter_info in ./
insert_block.module - Implementation of hook_filter_info().
File
- ./
insert_block.module, line 48 - Insert blocks into the body of a node
Code
function _insert_block($text, $filter, $format) {
global $user;
if (preg_match_all("/\\[block:([^=\\]]+)=?([^\\]]*)?\\]/i", $text, $match)) {
$block_roles = _insert_block_roles();
foreach ($match[2] as $key => $value) {
$raw_tags[] = $match[0][$key];
$module = $match[1][$key];
$delta = $match[2][$key];
// see comments on http://api.drupal.org/api/drupal/developer--theme.php/function/theme_block/7
$replacement = '';
if ($block = block_load($module, $delta)) {
$check_roles = !empty($filter->settings['check_roles']);
// If a block has no roles associated, it is displayed for every role.
// For blocks with roles associated, if none of the user's roles matches
// the settings from this block, remove it from the block list.
if ($check_roles && isset($block_roles[$block->module][$block->delta]) && !array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
// No match.
$block = NULL;
}
if ($block) {
$block_content = _block_render_blocks(array(
$block,
));
$build = _block_get_renderable_array($block_content);
$replacement = drupal_render($build);
}
}
$repl[] = $replacement;
}
return str_replace($raw_tags, $repl, $text);
}
return $text;
}