You are here

function block_inject_do_injection in Block Inject 7

Helper function that prepares and calls the injection on a node.

Parameters

$node: The node object that gets injected

$injectable: The injectable that goes into the node's body field

Return value

string The markup of the injected body field.

2 calls to block_inject_do_injection()
block_inject_node_view in ./block_inject.module
Implements hook_node_view().
block_inject_panels_pane_content_alter in ./block_inject.module
Implements hook_panels_pane_content_alter().

File

./block_inject.module, line 224
The Block Inject module functions.

Code

function block_inject_do_injection($node, $injectable) {

  // Check for exceptions.
  $exception = block_inject_green_light($node->nid);
  $go_ahead = FALSE;
  if (empty($exception)) {
    $go_ahead = TRUE;
  }
  elseif ($exception['bi_id'] != $injectable->id) {
    $go_ahead = TRUE;
  }
  if (!$go_ahead) {
    return FALSE;
  }

  // Return the blocks for each region to be injected into a variable.
  $region = block_get_blocks_by_region('block_inject-' . $injectable->id);

  // Prepare the attributes for the region div.
  $classes = array(
    'block-inject',
    'block-inject-' . $injectable->id,
  );
  $attributes = array(
    'id' => 'block-inject-' . $injectable->id,
    'class' => $classes,
  );

  // Create hook_block_inject_attributes_alter($attributes).
  $clearfix = true;
  $vars = array(
    'node' => clone $node,
    'attributes' => &$attributes,
    'clearfix' => &$clearfix,
  );
  drupal_alter('block_inject_attributes', $vars);

  // Get the body field.
  $body = block_inject_get_body_from_node($node);

  // Check for default conditions for offset.
  $offset = 0;
  $condition = block_inject_process_condition($node->type, $body);
  if ($condition) {
    $offset = $condition;
  }

  // Check if there is an individual offset on the node.
  $get_offset = block_inject_get_offset($node->nid);
  if (isset($get_offset)) {
    $offset = $offset + $get_offset['offset'];
  }

  // Try the injection and return the injected body.
  if ($render = block_inject_node($region, $body, $offset, $attributes, $clearfix)) {
    return $render;
  }
}