You are here

public function Entity::render in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::render()
  2. 9 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 178

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->entityTypeManager
        ->getStorage($this->entityType)
        ->load($target_id)) {
        $target_entity = $entity;
      }
    }
    else {
      if ($entity = $this->entityRepository
        ->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->entityTypeManager
        ->getViewBuilder($this->entityType);
      return $view_builder
        ->view($target_entity, $this->options['view_mode']);
    }
  }
  return [];
}