You are here

function ds_extras_render_panel_layout in Display Suite 7

Render the entity through the Panels layout.

1 string reference to 'ds_extras_render_panel_layout'
_ds_extras_theme_registry_alter in modules/ds_extras/ds_extras.registry.inc
Implements hook_theme_registry_alter().

File

modules/ds_extras/ds_extras.module, line 954
Display Suite extras main functions.

Code

function ds_extras_render_panel_layout(&$vars) {
  static $displays = array();
  if (isset($vars['elements']) && isset($vars['elements']['#bundle']) && ($layout = ds_get_layout($vars['elements']['#entity_type'], $vars['elements']['#bundle'], $vars['elements']['#view_mode']))) {
    if (empty($layout['settings']['ds_panels'])) {
      return;
    }
    $entity_type = $vars['elements']['#entity_type'];
    $bundle = $vars['elements']['#bundle'];
    $view_mode = $vars['elements']['#view_mode'];
    $element = '#' . $entity_type;
    if ($entity_type == 'user') {
      $element = '#account';
    }
    if ($entity_type == 'taxonomy_term') {
      $element = '#term';
    }

    // Compatibility with #entity elements.
    if (empty($vars['elements'][$element]) && !empty($vars['elements']['#entity'])) {
      $element = '#entity';
    }
    $entity = $vars['elements'][$element];
    ctools_include('plugins', 'panels');
    $contexts = array();

    // Add entity context to begin with.
    ds_create_entity_context($entity_type, $entity, $contexts);

    // Load the display.
    $did = $layout['settings']['did'];
    if (!isset($displays[$did])) {
      $display = panels_load_display($did);
      $display->entity_type = $entity_type;
      $display->bundle = $bundle;
      $display->view_mode = $view_mode;
      $displays[$did] = $display;
    }
    else {
      $display = $displays[$did];
    }
    $display->context = $contexts;
    $info = entity_extract_ids($entity_type, $entity);
    $display->entity_id = $info[0];

    // Add the panels template file as the theme hook suggestion.
    $vars['theme_hook_suggestion'] = $layout['settings']['theme'];

    // Add css ID.
    $vars['css_id'] = $layout['settings']['css_id'];

    // Add classes.
    $class = array();
    $class[] = check_plain($layout['settings']['class']);

    // Add sticky class.
    if ($layout['settings']['sticky'] && $entity->sticky) {
      $class[] = 'sticky';
    }
    $vars['class'] = !empty($class) ? ' ' . implode(' ', $class) : '';

    // Flexible layouts.
    if ($layout['settings']['theme'] == 'panels_flexible') {
      $vars['settings'] = $vars['renderer'] = '';
      $vars['display'] = $display;
      $panels_layout = str_replace('panels-', '', $layout['layout']);
      $vars['layout'] = panels_get_layout($panels_layout);
      $vars['theme_hook_suggestion'] = 'panels_flexible';
    }

    // Responsive layouts.
    if ($layout['settings']['theme'] == 'layout_responsive') {
      $vars['settings'] = $vars['renderer'] = '';
      $vars['display'] = $display;
      $vars['layout'] = panels_get_layout($layout['layout']);
      $vars['theme_hook_suggestion'] = 'layout_responsive';
    }

    // Load renderer.
    $pipeline = $layout['settings']['pipeline'];
    $renderer = panels_get_renderer($pipeline, $display);

    // Attach out-of-band data first.
    $renderer
      ->add_meta();
    $cache = FALSE;
    $cacheable = isset($renderer->display->cache['method']) && !empty($renderer->display->cache['method']);
    if ($cacheable) {
      $cache = panels_get_cached_content($renderer->display, $renderer->display->args, $renderer->display->context);
      if ($cache) {
        $content = $cache->content;
      }
    }

    // If no content is found from cache, call the $renderer
    // methods. In display has a cache setting, store it into cache table.
    if ($cache === FALSE) {
      $renderer
        ->prepare();
      $renderer
        ->render_panes();
      $renderer
        ->render_regions();
      $content = $renderer->rendered['regions'];
      if ($cacheable) {
        $cache = new panels_cache_object();
        $cache
          ->set_content($content);
        panels_set_cached_content($cache, $renderer->display, $renderer->display->args, $renderer->display->context);
      }
    }

    // Overwrite $vars['content'].
    $vars['content'] = $content;
  }
}