function EntityField::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
File
- 
              modules/
ctools_block/ src/ Plugin/ Block/ EntityField.php, line 136  
Class
- EntityField
 - Provides a block to a field on an entity.
 
Namespace
Drupal\ctools_block\Plugin\BlockCode
public function build() {
  /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
  $entity = $this->getContextValue('entity');
  $build = [];
  /** @var \Drupal\Core\Field\FieldItemListInterface $field */
  $field = $entity->{$this->fieldName};
  $display_settings = $this->getConfiguration()['formatter'];
  $build['field'] = $field->view($display_settings);
  // Set the cache data appropriately.
  $build['#cache']['contexts'] = $this->getCacheContexts();
  $build['#cache']['tags'] = $this->getCacheTags();
  $build['#cache']['max-age'] = $this->getCacheMaxAge();
  return $build;
}