You are here

function panels_renderer_standard::prepare_panes in Panels 7.3

Same name and namespace in other branches
  1. 6.3 plugins/display_renderers/panels_renderer_standard.class.php \panels_renderer_standard::prepare_panes()

Prepare the list of panes to be rendered, accounting for visibility/access settings and rendering order.

This method represents the standard approach for determining the list of panes to be rendered that is compatible with all parts of the Panels architecture. It first applies visibility & access checks, then sorts panes into their proper rendering order, and returns the result as an array.

Inheriting classes should override this method if that renderer needs to regularly make additions to the set of panes that will be rendered.

Parameters

array $panes: An associative array of pane data (stdClass objects), keyed on pane id.

Return value

array An associative array of panes to be rendered, keyed on pane id and sorted into proper rendering order.

2 calls to panels_renderer_standard::prepare_panes()
panels_renderer_ipe::prepare_panes in panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
Prepare the list of panes to be rendered, accounting for visibility/access settings and rendering order.
panels_renderer_standard::prepare in plugins/display_renderers/panels_renderer_standard.class.php
Prepare the attached display for rendering.
1 method overrides panels_renderer_standard::prepare_panes()
panels_renderer_ipe::prepare_panes in panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
Prepare the list of panes to be rendered, accounting for visibility/access settings and rendering order.

File

plugins/display_renderers/panels_renderer_standard.class.php, line 248

Class

panels_renderer_standard

Code

function prepare_panes($panes) {
  ctools_include('content');

  // Use local variables as writing to them is very slightly faster.
  $first = $normal = $last = array();

  // Prepare the list of panes to be rendered.
  foreach ($panes as $pid => $pane) {
    if (empty($this->admin)) {

      // TODO remove in 7.x and ensure the upgrade path weeds out any stragglers; it's been long enough.
      $pane->shown = !empty($pane->shown);

      // Guarantee this field exists.
      // If this pane is not visible to the user, skip out and do the next one.
      if (!$pane->shown || !panels_pane_access($pane, $this->display)) {
        continue;
      }
    }

    // If the pane's subtype is unique, get it so that
    // hook_ctools_content_subtype_alter() and/or
    // hook_ctools_block_info() will be called.
    if ($pane->type != $pane->subtype) {
      $content_type = ctools_content_get_subtype($pane->type, $pane->subtype);
    }
    else {
      $content_type = ctools_get_content_type($pane->type);
    }

    // If this pane wants to render last, add it to the $last array. We allow
    // this because some panes need to be rendered after other panes,
    // primarily so they can do things like the leftovers of forms.
    if (!empty($content_type['render last'])) {
      $last[$pid] = $pane;
    }
    elseif (!empty($content_type['render first'])) {
      $first[$pid] = $pane;
    }
    else {
      $normal[$pid] = $pane;
    }
  }
  $this->prepared['panes'] = $first + $normal + $last;

  // Allow other modules the alter the prepared panes array.
  drupal_alter('panels_panes_prepared', $this->prepared['panes'], $this);
  return $this->prepared['panes'];
}