function ExtraFieldBlock::build
Same name in other branches
- 9 core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::build()
- 10 core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::build()
- 11.x core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::build()
File
-
core/
modules/ layout_builder/ src/ Plugin/ Block/ ExtraFieldBlock.php, line 117
Class
- ExtraFieldBlock
- Provides a block that renders an extra field from an entity.
Namespace
Drupal\layout_builder\Plugin\BlockCode
public function build() {
$entity = $this->getEntity();
// Add a placeholder to replace after the entity view is built.
// @see layout_builder_entity_view_alter().
$extra_fields = $this->entityFieldManager
->getExtraFields($entity->getEntityTypeId(), $entity->bundle());
if (!isset($extra_fields['display'][$this->fieldName])) {
$build = [];
}
else {
$build = [
'#extra_field_placeholder_field_name' => $this->fieldName,
// Always provide a placeholder. The Layout Builder will NOT invoke
// hook_entity_view_alter() so extra fields will not be added to the
// render array. If the hook is invoked the placeholder will be
// replaced.
// @see ::replaceFieldPlaceholder()
'#markup' => $this->t('Placeholder for the @preview_fallback', [
'@preview_fallback' => $this->getPreviewFallbackString(),
]),
];
}
CacheableMetadata::createFromObject($this)->applyTo($build);
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.