You are here

public function AttachedRenderingBlock::build in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/AttachedRenderingBlock.php \Drupal\render_attached_test\Plugin\Block\AttachedRenderingBlock::build()

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

core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/AttachedRenderingBlock.php, line 30
Contains \Drupal\render_attached_test\Plugin\Block\AttachedRenderingBlock.

Class

AttachedRenderingBlock
A block we can use to test caching of #attached headers.

Namespace

Drupal\render_attached_test\Plugin\Block

Code

public function build() {

  // Grab test attachment fixtures from
  // Drupal\render_attached_test\Controller\RenderAttachedTestController.
  $controller = new RenderAttachedTestController();
  $attached = BubbleableMetadata::mergeAttachments($controller
    ->feed(), $controller
    ->head());
  $attached = BubbleableMetadata::mergeAttachments($attached, $controller
    ->header());
  $attached = BubbleableMetadata::mergeAttachments($attached, $controller
    ->teapotHeaderStatus());

  // Return some arbitrary markup so the block doesn't disappear.
  $attached['#markup'] = 'Markup from attached_rendering_block.';
  return $attached;
}