You are here

public function ContentEmbedBlock::build in Content Browser 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/ContentEmbedBlock.php, line 207

Class

ContentEmbedBlock
Provides the "Content Embed" block.

Namespace

Drupal\content_browser\Plugin\Block

Code

public function build() {
  $build = [];
  $view_builder = \Drupal::entityTypeManager()
    ->getViewBuilder('node');
  foreach ($this
    ->getDefaultNids() as $nid) {

    /** @var \Drupal\node\Entity\Node $node */
    $node = Node::load($nid);
    if ($node && $node
      ->access('view')) {
      if (isset(static::$recursiveRenderDepth[$nid])) {
        static::$recursiveRenderDepth[$nid]++;
      }
      else {
        static::$recursiveRenderDepth[$nid] = 1;
      }

      // Protect ourselves from recursive rendering.
      if (static::$recursiveRenderDepth[$nid] > static::RECURSIVE_RENDER_LIMIT) {
        return $build;
      }
      $build[] = $view_builder
        ->view($node, $this->configuration['view_mode']);
    }
  }
  return $build;
}