function ExtraFieldBlock::preRenderBlock

Pre-render callback to ensure empty extra_field_block's are not rendered.

Attributes

#[TrustedCallback]

Parameters

array $block_build: The original block render array.

Return value

array The modified block render array.

File

core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php, line 192

Class

ExtraFieldBlock
Provides a block that renders an extra field from an entity.

Namespace

Drupal\layout_builder\Plugin\Block

Code

public static function preRenderBlock(array $block_build) : array {
  $content = $block_build['content'] ?? NULL;
  if ($content === NULL || Element::isEmpty($content)) {
    // Block content is empty, abort rendering the whole block and preserve
    // cache metadata.
    // @see \Drupal\Core\Render\Renderer::doRender
    $block_build['#printed'] = TRUE;
  }
  return $block_build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.