You are here

public function Entity::render in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::render()

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides AreaPluginBase::render

File

core/modules/views/src/Plugin/views/area/Entity.php, line 159
Contains \Drupal\views\Plugin\views\area\Entity.

Class

Entity
Provides an area handler which renders an entity in a certain view mode.

Namespace

Drupal\views\Plugin\views\area

Code

public function render($empty = FALSE) {
  if (!$empty || !empty($this->options['empty'])) {

    // @todo Use a method to check for tokens in
    //   https://www.drupal.org/node/2396607.
    if (strpos($this->options['target'], '{{') !== FALSE) {

      // We cast as we need the integer/string value provided by the
      // ::tokenizeValue() call.
      $target_id = (string) $this
        ->tokenizeValue($this->options['target']);
      if ($entity = $this->entityManager
        ->getStorage($this->entityType)
        ->load($target_id)) {
        $target_entity = $entity;
      }
    }
    else {
      if ($entity = $this->entityManager
        ->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
        $target_entity = $entity;
      }
    }
    if (isset($target_entity) && (!empty($this->options['bypass_access']) || $target_entity
      ->access('view'))) {
      $view_builder = $this->entityManager
        ->getViewBuilder($this->entityType);
      return $view_builder
        ->view($target_entity, $this->options['view_mode']);
    }
  }
  return [];
}