Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
custom_elements
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
custom_elements
Commits
8fad83c4
Commit
8fad83c4
authored
2 months ago
by
Roderik Muit
Committed by
Wolfgang Ziegler
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3504944
by roderik: Fix error when enabling layout_builder
parent
bca11271
No related branches found
No related tags found
1 merge request
!115
Skip entity_type_alter until layout_builder_install() has executed
Pipeline
#468121
passed with warnings
6 days ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
custom_elements.module
+31
-4
31 additions, 4 deletions
custom_elements.module
tests/src/Kernel/CustomElementGeneratorTest.php
+2
-0
2 additions, 0 deletions
tests/src/Kernel/CustomElementGeneratorTest.php
with
33 additions
and
4 deletions
custom_elements.module
+
31
−
4
View file @
8fad83c4
...
...
@@ -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().
*/
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/CustomElementGeneratorTest.php
+
2
−
0
View file @
8fad83c4
...
...
@@ -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'
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment