You are here

function PanelizerEntityDefault::render_entity in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::render_entity()

Render the panels display for a given panelizer entity.

Parameters

stdClass $entity: A fully-loaded entity object controlled by panelizer.

array $args: Optional array of arguments to pass to the panels display.

string $address: An optional address to send to the renderer to use for addressable content.

array $extra_contexts: An optional array of extra context objects that will be added to the display.

Return value

array If the entity isn't panelized, this returns NULL. Otherwise, it returns an associative array as meant for use with CTools with the following keys:

  • 'content': String containing the rendered panels display output.
  • 'no_blocks': Boolean defining if the panels display wants to hide core blocks or not when being rendered.

Overrides PanelizerEntityInterface::render_entity

1 call to PanelizerEntityDefault::render_entity()
PanelizerEntityNode::render_entity in plugins/entity/PanelizerEntityNode.class.php
Render the panels display for a given panelizer entity.
1 method overrides PanelizerEntityDefault::render_entity()
PanelizerEntityNode::render_entity in plugins/entity/PanelizerEntityNode.class.php
Render the panels display for a given panelizer entity.

File

plugins/entity/PanelizerEntityDefault.class.php, line 3434
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

function render_entity($entity, $view_mode, $langcode = NULL, $args = array(), $address = NULL, $extra_contexts = array()) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);

  // Optionally substitute the view mode with another one.
  $substitute = $this
    ->get_substitute($view_mode, $bundle);
  if (!empty($substitute)) {
    $view_mode = $substitute;
  }

  // Nothing configured for this view mode.
  if (empty($entity->panelizer[$view_mode]) || empty($entity->panelizer[$view_mode]->display)) {
    return FALSE;
  }
  $panelizer = $entity->panelizer[$view_mode];
  $display = $panelizer->display;
  $display->context = $this
    ->get_contexts($panelizer, $entity) + $extra_contexts;
  $display->args = $args;
  $display->css_id = $panelizer->css_id;

  // This means the IPE will use our cache which means it will get appropriate
  // allowed content should it be selected.
  $display->cache_key = implode(':', array_filter(array(
    'panelizer',
    $this->entity_type,
    $entity_id,
    $view_mode,
    $revision_id,
  )));

  // Check to see if there is any CSS.
  if (!empty($panelizer->css)) {
    ctools_include('css');
    $filename = ctools_css_retrieve($display->cache_key);
    if (!$filename) {
      $filename = ctools_css_store($display->cache_key, $panelizer->css);
    }
    drupal_add_css($filename, array(
      'group' => CSS_THEME,
    ));
  }
  if ($view_mode == 'page_manager') {

    // We think this is handled as a page, so set the current page display.
    panels_get_current_page_display($display);
  }

  // Allow applications to alter the panelizer and the display before
  // rendering them.
  drupal_alter('panelizer_pre_render', $panelizer, $display, $entity);
  ctools_include('plugins', 'panels');
  $renderer = panels_get_renderer($panelizer->pipeline, $display);

  // If the IPE is enabled, but the user does not have access to edit
  // the entity, load the standard renderer instead.
  // Use class_parents so we don't try to autoload the class we are testing.
  $parents = class_parents($renderer);
  if (!empty($parents['panels_renderer_editor']) && (!$this
    ->panelizer_access('content', $entity, $view_mode) && !$this
    ->entity_access('update', $entity))) {
    $renderer = panels_get_renderer_handler('standard', $display);
  }
  $renderer->address = $address;
  $info = array(
    'content' => panels_render_display($display, $renderer),
    'no_blocks' => !empty($panelizer->no_blocks),
  );

  // Wait until the display is rendered above before trying to obtain the
  // title, this way the title "From pane" option will work.
  $info['title'] = $panelizer->display
    ->get_title();
  $info['classes_array'] = array();
  if (!empty($panelizer->css_class)) {
    foreach (explode(' ', $panelizer->css_class) as $class) {
      $class = ctools_context_keyword_substitute($class, array(), $display->context);
      if ($class) {
        $info['classes_array'][] = drupal_html_class($class);
      }
    }
  }
  if (!empty($parents['panels_renderer_editor'])) {
    $path = drupal_get_path('module', 'panelizer');
    ctools_add_js('panelizer-ipe', 'panelizer');
    drupal_add_js($path . "/js/panelizer-ipe.js", array(
      'group' => JS_LIBRARY,
    ));
    drupal_add_css($path . "/css/panelizer-ipe.css");
  }
  return $info;
}