You are here

public static function ExtraFieldBlock::replaceFieldPlaceholder in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::replaceFieldPlaceholder()
  2. 9 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\Block

Code

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);
    }
  }
}