function block_inject_node in Block Inject 7
Injects the region in the middle of the node.
Parameters
array $region: An array of the regions to be injected.
string $body: The body field to be injected in.
Return value
bool|string The injected body string or false if not enough paragraphs.
1 call to block_inject_node()
- block_inject_do_injection in ./
block_inject.module - Helper function that prepares and calls the injection on a node.
File
- ./
block_inject.module, line 292 - The Block Inject module functions.
Code
function block_inject_node($region, $body, $offset = 0, $attributes = array(), $clearfix = true) {
// Break up the body field string into an array of paragraphs.
$array_explode = explode("<p>", $body);
if ($array_explode[0] === "") {
unset($array_explode[0]);
}
// Return false if the number of paragraphs is not at least 4.
if (count($array_explode) < 4) {
return FALSE;
}
// Get the half number of the total number of paragraphs (round up).
$array_explode_half = round(count($array_explode) / 2);
// Add the attributes to the region renderable array
$region['#prefix'] = '<div ' . drupal_attributes($attributes) . '>';
$region['#suffix'] = '</div>';
// Add a clearfix div if requested
if ($clearfix === true) {
$region['#suffix'] .= '<div class="clearfix"></div>';
}
// Insert the renderable region array into the middle of the body field.
array_splice($array_explode, $array_explode_half + $offset, 0, render($region));
// Re-create the body field string with the region injected.
return block_inject_implode_paragraphs($array_explode);
}