function ExtraFieldBlock::replaceFieldPlaceholder
Same name in other branches
- 8.9.x core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::replaceFieldPlaceholder()
- 10 core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::replaceFieldPlaceholder()
- 11.x core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::replaceFieldPlaceholder()
Replaces all placeholders for a given field.
Parameters
array $build: The built render array for the elements.
array $built_field: The render array to replace the placeholder.
string $field_name: The field name.
See also
::build()
1 call to ExtraFieldBlock::replaceFieldPlaceholder()
- layout_builder_entity_view_alter in core/
modules/ layout_builder/ layout_builder.module - Implements hook_entity_view_alter().
File
-
core/
modules/ layout_builder/ src/ Plugin/ Block/ ExtraFieldBlock.php, line 165
Class
- ExtraFieldBlock
- Provides a block that renders an extra field from an entity.
Namespace
Drupal\layout_builder\Plugin\BlockCode
public static function replaceFieldPlaceholder(array &$build, array $built_field, $field_name) {
foreach (Element::children($build) as $child) {
if (isset($build[$child]['#extra_field_placeholder_field_name']) && $build[$child]['#extra_field_placeholder_field_name'] === $field_name) {
$placeholder_cache = CacheableMetadata::createFromRenderArray($build[$child]);
$built_cache = CacheableMetadata::createFromRenderArray($built_field);
$merged_cache = $placeholder_cache->merge($built_cache);
$build[$child] = $built_field;
$merged_cache->applyTo($build);
}
else {
static::replaceFieldPlaceholder($build[$child], $built_field, $field_name);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.