public function buildView(array &
$build, EntityDisplayWithLayoutInterface
$display) { $layout_definition =
$this->layoutPluginManager->
getDefinition($display->
getLayoutId(), FALSE
);
if ($layout_definition &&
$fields =
$this->
getFields($build,
$display, 'view'
)) { // Add the regions to the $build in the correct order.
$regions =
array_fill_keys($layout_definition->
getRegionNames(),
[]);
foreach ($fields as $name =>
$field) { // If the region is controlled by the layout, move the field from the
// top-level of $build into a region-specific section. Custom regions
// could be set by other code at run-time; these should be ignored.
// @todo Ideally the array structure would remain unchanged, see
// https://www.drupal.org/node/2846393.
if (isset($regions[$field['region'
]])) { $regions[$field['region'
]][$name] =
$build[$name];
unset($build[$name]);
} }