You are here

function block_inject_panels_pane_content_alter in Block Inject 7

Implements hook_panels_pane_content_alter().

File

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

Code

function block_inject_panels_pane_content_alter($content, $pane, $args, $contexts) {
  $pane_types = array(
    'entity_field',
    'node_content',
  );
  $pane_subtypes = array(
    'node:body',
    'node_content',
  );
  if (!in_array($pane->type, $pane_types)) {
    return;
  }
  if (!in_array($pane->subtype, $pane_subtypes)) {
    return;
  }
  if (!isset($contexts['argument_entity_id:node_1'])) {
    return;
  }
  $node = $contexts['argument_entity_id:node_1']->data;

  // Check if there is an injectable region for this node type.
  $injectable = block_inject_get_region_by_node_type($node->type);
  if (!$injectable) {
    return;
  }
  $render = block_inject_do_injection($node, $injectable);
  if (!$render) {
    return;
  }

  // For the body field panel pane.
  if ($pane->subtype === 'node:body') {
    $content->content[0]['#markup'] = $render;
  }

  // For the node content panel pane.
  if ($pane->subtype === 'node_content') {
    $content->content['body'][0]['#markup'] = $render;
  }
}