Skip to content
Snippets Groups Projects
Commit 8fad83c4 authored by Roderik Muit's avatar Roderik Muit Committed by Wolfgang Ziegler
Browse files

Issue #3504944 by roderik: Fix error when enabling layout_builder

parent bca11271
No related branches found
No related tags found
1 merge request!115Skip entity_type_alter until layout_builder_install() has executed
Pipeline #468121 passed with warnings
......@@ -11,9 +11,11 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\Markup;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Update\UpdateHookRegistry;
use Drupal\custom_elements\CustomElement;
use Drupal\custom_elements\CustomElementsEntityViewDisplay;
use Drupal\custom_elements\CustomElementsLayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
/**
* Implements hook_theme().
......@@ -150,11 +152,24 @@ function custom_elements_prepare_slots_as_vue_3(CustomElement $custom_element) {
* @see custom_elements_module_implements_alter()
*/
function custom_elements_entity_type_alter(array &$entity_types) {
// Use the right class depending on layout builder being used.
$class = \Drupal::moduleHandler()->moduleExists('layout_builder') ? CustomElementsLayoutBuilderEntityViewDisplay::class : CustomElementsEntityViewDisplay::class;
// Check if this call is made during layout_builder installation; changing
// the entity class would make the loadMultiple() call in
// layout_builder_install() fail fatally in that case. This check depends on
// ModuleInstaller implementation details, i.e. entity info is
// - (re)built before the module (version) is registered
// - not rebuilt between registering the module and invoking hook_install.
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
$entity_types['entity_view_display']
->setClass($class);
$layout_builder_module_install_in_progress =
$entity_types['entity_view_display']->getClass() === LayoutBuilderEntityViewDisplay::class
&& \Drupal::service('update.update_hook_registry')->getInstalledVersion('layout_builder')
== UpdateHookRegistry::SCHEMA_UNINSTALLED;
if (!$layout_builder_module_install_in_progress) {
// Use the right class depending on layout builder being used.
$class = \Drupal::moduleHandler()->moduleExists('layout_builder') ? CustomElementsLayoutBuilderEntityViewDisplay::class : CustomElementsEntityViewDisplay::class;
$entity_types['entity_view_display']
->setClass($class);
}
}
/**
......@@ -182,6 +197,18 @@ function custom_elements_module_implements_alter(&$implementations, $hook) {
}
}
/**
* Implements hook_modules_installed().
*
* @see custom_elements_entity_type_alter()
*/
function custom_elements_modules_installed($modules, $is_syncing) {
if (in_array('layout_builder', $modules, TRUE)) {
// Rebuild info that was not changed yet during installation.
\Drupal::entityTypeManager()->clearCachedDefinitions();
}
}
/**
* Implements hook_entity_view_display_alter().
*/
......
......@@ -72,6 +72,8 @@ class CustomElementGeneratorTest extends KernelTestBase {
*/
protected function setUp(): void {
parent::setUp();
// custom_elements_entity_type_alter() needs a layout_builder version.
\Drupal::service('update.update_hook_registry')->setInstalledVersion('layout_builder', '12345');
$this->installEntitySchema('user');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment