From 68f9fd50e86339fda754386248d9f1378de64d6e Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 20 Sep 2018 13:16:43 +0100 Subject: [PATCH] Issue #2954776 by neclimdul, tim.plunkett, zenimagine, tedbow: Can not uninstall Field Layout while Layout Builder is installed --- .../modules/field_layout/field_layout.install | 13 ++++++--- .../src/Kernel/FieldLayoutUninstallTest.php | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 core/modules/field_layout/tests/src/Kernel/FieldLayoutUninstallTest.php diff --git a/core/modules/field_layout/field_layout.install b/core/modules/field_layout/field_layout.install index 5956bf1095..88882d3928 100644 --- a/core/modules/field_layout/field_layout.install +++ b/core/modules/field_layout/field_layout.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface; @@ -15,8 +16,10 @@ */ function field_layout_install() { // Ensure each entity display has a layout. - $entity_save = function (EntityDisplayWithLayoutInterface $entity) { - $entity->ensureLayout()->save(); + $entity_save = function (EntityDisplayInterface $entity) { + if ($entity instanceof EntityDisplayWithLayoutInterface) { + $entity->ensureLayout()->save(); + } }; array_map($entity_save, EntityViewDisplay::loadMultiple()); array_map($entity_save, EntityFormDisplay::loadMultiple()); @@ -31,8 +34,10 @@ function field_layout_install() { function field_layout_uninstall() { // Reset each entity display to use the one-column layout to best approximate // the absence of layouts. - $entity_save = function (EntityDisplayWithLayoutInterface $entity) { - $entity->setLayoutId('layout_onecol')->save(); + $entity_save = function (EntityDisplayInterface $entity) { + if ($entity instanceof EntityDisplayWithLayoutInterface) { + $entity->setLayoutId('layout_onecol')->save(); + } }; array_map($entity_save, EntityViewDisplay::loadMultiple()); array_map($entity_save, EntityFormDisplay::loadMultiple()); diff --git a/core/modules/field_layout/tests/src/Kernel/FieldLayoutUninstallTest.php b/core/modules/field_layout/tests/src/Kernel/FieldLayoutUninstallTest.php new file mode 100644 index 0000000000..387e6b235b --- /dev/null +++ b/core/modules/field_layout/tests/src/Kernel/FieldLayoutUninstallTest.php @@ -0,0 +1,29 @@ +installSchema('user', 'users_data'); + + // Setup layout builder and same displays. + $this->installLayoutBuilder(); + + // Ensure install hook can handle displays without a layout. + $this->container->get('module_installer')->install(['field_layout']); + + // Ensure uninstall hook can handle displays without a layout. + $this->container->get('module_installer')->uninstall(['field_layout']); + } + +} -- GitLab