You are here

class esi_panels_renderer_standard in ESI: Edge Side Includes 7.3

Extend the panels_renderer_standard class, to override render_layout(). The standard renderer renders the panes, then immediately renders the regions. We need to catch the panes after they're individually rendered, but before they're bundled together into regions.

Hierarchy

Expanded class hierarchy of esi_panels_renderer_standard

1 string reference to 'esi_panels_renderer_standard'
esi_standard.inc in modules/esi_panels/plugins/display_renderers/esi_standard.inc

File

modules/esi_panels/plugins/display_renderers/esi_panels_renderer_standard.class.php, line 14
Replacement for standard editor.

View source
class esi_panels_renderer_standard extends panels_renderer_standard {

  /**
   * 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 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.
   *
   * @param array $panes
   *   An associative array of pane data (stdClass objects), keyed on pane id.
   *
   * @return array
   *   An associative array of panes to be rendered, keyed on pane id and sorted
   *   into proper rendering order.
   */
  function prepare_panes($panes) {

    // Override parent::prepare_panes, so that any access-controls are not
    // applied to ESI panes. This ensures that panes are al
    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 displayed, skip out and do the next one.
        // Do not handle user-access controls here for ESI panes (handle in the
        // ESI rendering).
        if (!$this
          ->pane_should_be_rendered($pane)) {
          continue;
        }
      }
      $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;
      }
      else {
        if (!empty($content_type['render first'])) {
          $first[$pid] = $pane;
        }
        else {
          $normal[$pid] = $pane;
        }
      }
    }
    $this->prepared['panes'] = $first + $normal + $last;
    return $this->prepared['panes'];
  }

  /**
   * Test if a pane (or ESI tag) should be rendered. Normal panes are checked
   * for visibility and access-control rules. Panes rendered by ESI are just
   * checked for visibility.
   */
  function pane_should_be_rendered($pane) {
    if (!$pane->shown) {
      return FALSE;
    }
    elseif (!empty($pane->cache) && $pane->cache['method'] == 'esi') {

      // ESI panes are always rendered (access callbacks)
      return TRUE;
    }
    return panels_pane_access($pane, $this->display);
  }

  /**
   * Perform display/layout-level render operations.
   *
   * This method triggers all the inner pane/region rendering processes, passes
   * that to the layout plugin's theme callback, and returns the rendered HTML.
   *
   * If display-level caching is enabled and that cache is warm, this method
   * will not be called.
   *
   * @return string
   *   The HTML string representing the entire rendered, themed panel.
   */
  function render_layout() {
    if (empty($this->prep_run)) {
      $this
        ->prepare();
    }
    $this
      ->render_panes();
    $this
      ->handle_esi();
    $this
      ->render_regions();
    if ($this->admin && !empty($this->plugins['layout']['admin theme'])) {
      $theme = $this->plugins['layout']['admin theme'];
    }
    else {
      $theme = $this->plugins['layout']['theme'];
    }
    $this->rendered['layout'] = theme($theme, array(
      'css_id' => check_plain($this->display->css_id),
      'content' => $this->rendered['regions'],
      'settings' => $this->display->layout_settings,
      'display' => $this->display,
      'layout' => $this->plugins['layout'],
      'renderer' => $this,
    ));
    return $this->prefix . $this->rendered['layout'] . $this->suffix;
  }

  /**
   * Parse the rendered panes, replacing the ESI-handled panes with ESI tags.
   */
  function handle_esi() {
    foreach ($this->prepared['panes'] as $pid => $pane) {
      if (!empty($pane->cache) && $pane->cache['method'] == 'esi') {
        $this
          ->handle_esi_pane($pane);
      }
    }
  }

  /**
   * Replace a pane's rendered content with ESI content.
   */
  function handle_esi_pane($pane) {
    $url = url(esi_panels_url($pane, $this->display), array(
      'absolute' => TRUE,
    ));
    $render = array(
      '#type' => 'esi',
      '#url' => $url,
    );
    $this->rendered['panes'][$pane->pid] = drupal_render($render);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
esi_panels_renderer_standard::handle_esi function Parse the rendered panes, replacing the ESI-handled panes with ESI tags.
esi_panels_renderer_standard::handle_esi_pane function Replace a pane's rendered content with ESI content.
esi_panels_renderer_standard::pane_should_be_rendered function Test if a pane (or ESI tag) should be rendered. Normal panes are checked for visibility and access-control rules. Panes rendered by ESI are just checked for visibility.
esi_panels_renderer_standard::prepare_panes function Prepare the list of panes to be rendered, accounting for visibility/access settings and rendering order. Overrides panels_renderer_standard::prepare_panes
esi_panels_renderer_standard::render_layout function Perform display/layout-level render operations. Overrides panels_renderer_standard::render_layout
panels_renderer_standard::$admin property TRUE if this renderer is rendering in administrative mode which will allow layouts to have extra functionality. 1
panels_renderer_standard::$display property The fully-loaded Panels display object that is to be rendered. "Fully loaded" is defined as: 1. Having been produced by panels_load_displays(), whether or this page request or at some time in the past and the object was exported. 2. Having…
panels_renderer_standard::$meta_location property Where to add standard meta information. There are three possibilities:
panels_renderer_standard::$plugin property The plugin that defines this handler.
panels_renderer_standard::$plugins property An associative array of loaded plugins. Used primarily as a central location for storing plugins that require additional loading beyond reading the plugin definition, which is already statically cached by ctools_get_plugins(). An example is layout…
panels_renderer_standard::$prefix property Include rendered HTML prior to the layout.
panels_renderer_standard::$prepared property A multilevel array of data prepared for rendering. The first level of the array indicates the type of prepared data. The standard renderer populates and uses two top-level keys, 'panes' and 'regions':
panels_renderer_standard::$prep_run property Boolean state variable, indicating whether or not the prepare() method has been run.
panels_renderer_standard::$rendered property A multilevel array of rendered data. The first level of the array indicates the type of rendered data, typically with up to three keys: 'layout', 'regions', and 'panes'. The relevant rendered data is stored as the value…
panels_renderer_standard::$show_empty_layout property Boolean flag indicating whether to render the layout even if all rendered regions are blank. If FALSE, the layout renders as an empty string (without prefix or suffix) if not in administrative mode.
panels_renderer_standard::$suffix property Include rendered HTML after the layout.
panels_renderer_standard::add_css function Add CSS information to the renderer.
panels_renderer_standard::add_meta function Attach out-of-band page metadata (e.g., CSS and JS). 1
panels_renderer_standard::get_panels_storage_op_for_ajax function Get the Panels storage oparation for a given renderer AJAX method. 1
panels_renderer_standard::init function Receive and store the display object to be rendered.
panels_renderer_standard::prepare function Prepare the attached display for rendering. 1
panels_renderer_standard::prepare_regions function Prepare the list of regions to be rendered.
panels_renderer_standard::render function Build inner content, then hand off to layout-specified theme function for final render step. 1
panels_renderer_standard::render_pane function Render a pane using its designated style. 1
panels_renderer_standard::render_panes function Render all prepared panes, first by dispatching to their plugin's render callback, then handing that output off to the pane's style plugin. 1
panels_renderer_standard::render_pane_content function Render the interior contents of a single pane. 1
panels_renderer_standard::render_region function Render a single panel region. 1
panels_renderer_standard::render_regions function Render all prepared regions, placing already-rendered panes into their appropriate positions therein. 1