Skip to content
Snippets Groups Projects
Commit f8bc25b8 authored by Wolfgang Ziegler's avatar Wolfgang Ziegler
Browse files

Issue #3053803: Fix extra fields to be rendered via layout builder.

parent 09c3b277
Branches
Tags 8.x-2.0-alpha3
No related merge requests found
<?php
/**
* @file
* Module install file.
*/
/**
* Implements hook_install().
*/
function custom_elements_install() {
// Make sure our module comes after layout_builder.
// @see custom_elements_module_implements_alter().
module_set_weight('custom_elements', 10);
}
/**
* Set module weight.
*/
function custom_elements_update_8201() {
// Make sure our module comes after layout_builder.
// @see custom_elements_module_implements_alter().
module_set_weight('custom_elements', 10);
}
......@@ -76,6 +76,14 @@ function custom_elements_module_implements_alter(&$implementations, $hook) {
unset($implementations['custom_elements']);
$implementations['custom_elements'] = $group;
}
// Be sure our entity_view_alter hook comes last, even after layout builder
// which also tries to make it come last.
// @see custom_elements_install().
if ($hook === 'entity_view_alter') {
$group = $implementations['custom_elements'];
unset($implementations['custom_elements']);
$implementations['custom_elements'] = $group;
}
}
/**
......@@ -95,5 +103,13 @@ function custom_elements_entity_view_alter(array &$build, Drupal\Core\Entity\Ent
// Alter the build array to apply custom elements rendering.
if (!empty($build['#custom_elements_enabled'])) {
$build['#theme'] = 'custom_element';
// Add layout builder sections, but be sure to do so once extra fields
// were added by layout_builder_entity_view_alter()
// @see custom_elements_module_implements_alter().
// @see \Drupal\custom_elements\CustomElementsEntityViewDisplayTrait::buildMultipleViaCustomElements()
if (!empty($build['#custom_elements_add_layout_builder_section'])) {
$build['#custom_element']->setSlot('sections', $build['_layout_builder']);
}
}
}
......@@ -31,9 +31,10 @@ trait CustomElementsEntityViewDisplayTrait {
$build['#view_mode'] = $this->originalMode;
$build['#custom_element'] = $this->getCustomElementGenerator()->generate($entity, $build['#view_mode']);
// Add layout build sections unless already done so.
if (isset($build['_layout_builder']) && empty($build['#custom_element']->getSlot('sections'))) {
$build['#custom_element']->setSlot('sections', $build['_layout_builder']);
// Add layout build sections later during entity_view_alter().
// @see custom_elements_entity_view_alter()
if (isset($build['_layout_builder']) && !isset($build['#custom_elements_add_layout_builder_section'])) {
$build['#custom_elements_add_layout_builder_section'] = TRUE;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment