You are here

public static function FieldBlock::fieldBlockPostRenderCache in Field as Block 8

#post_render_cache callback, temporarily stores a field's render array in a static variable and returns the original element as post render cache callbacks are supposed to do.

Note that this is an atypical way to use the post render cache mechanism. Post render cache is meant to allow modules to dynamically alter pieces of cached content. Here we use it as some kind of context-aware cache, because the cached field will only be retrieved and displayed as a block when the entity is viewed.

Parameters

mixed[] $element: The render array being rendered.

mixed[] $context: Array containing the fieldblock ID and the field's render array.

Return value

mixed[] The render array being rendered.

File

src/Plugin/Block/FieldBlock.php, line 82
Contains \Drupal\fieldblock\Plugin\Block\FieldBlock.

Class

FieldBlock
Provides a fieldblock.

Namespace

Drupal\fieldblock\Plugin\Block

Code

public static function fieldBlockPostRenderCache(array $element, array $context) {
  self::setFieldBlock($context['fieldblock_id'], $context['build']);
  return $element;
}