You are here

function oa_related_panelizer_pre_render_alter in Open Atrium Related Content 7.2

Implements hook_panelizer_pre_render_alter().

Adds the oa_related field panels pane right after the body field

File

./oa_related.module, line 207

Code

function oa_related_panelizer_pre_render_alter(&$panelizer, $display, $entity) {
  if (!empty($entity->field_oa_related)) {
    $found = FALSE;
    foreach ($display->content as $index => $panel) {
      if ($panel->type == 'entity_field' && $panel->subtype == 'node:field_oa_related') {
        $found = TRUE;
        break;
      }
    }
    if (!$found) {
      foreach ($display->content as $index => $panel) {
        if ($panel->type == 'entity_field' && $panel->subtype == 'node:body') {

          // found the body field so add a field_oa_related pane right after it
          $pane = oa_related_default_pane($entity, 'field_oa_related');
          $pid = uniqid();
          $pane->pid = $pid;
          $pane->uuid = $pid;

          // set the display panel to the same region as the body field
          $pane->panel = $panel->panel;

          // add new pane to list of available panes
          $panelizer->display->content[$pid] = $pane;

          // finally, insert the pid reference of the new pane into the correct spot
          // within the region right after the body position
          $i = array_search($index, $panelizer->display->panels[$panel->panel]);
          array_splice($panelizer->display->panels[$panel->panel], $i + 1, 0, array(
            $pid,
          ));
          break;
        }
      }
    }
  }
}