Unverified Commit 68f9fd50 authored by alexpott's avatar alexpott

Issue #2954776 by neclimdul, tim.plunkett, zenimagine, tedbow: Can not...

Issue #2954776 by neclimdul, tim.plunkett, zenimagine, tedbow: Can not uninstall Field Layout while Layout Builder is installed
parent 586d121c
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface; use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
...@@ -15,8 +16,10 @@ ...@@ -15,8 +16,10 @@
*/ */
function field_layout_install() { function field_layout_install() {
// Ensure each entity display has a layout. // Ensure each entity display has a layout.
$entity_save = function (EntityDisplayWithLayoutInterface $entity) { $entity_save = function (EntityDisplayInterface $entity) {
$entity->ensureLayout()->save(); if ($entity instanceof EntityDisplayWithLayoutInterface) {
$entity->ensureLayout()->save();
}
}; };
array_map($entity_save, EntityViewDisplay::loadMultiple()); array_map($entity_save, EntityViewDisplay::loadMultiple());
array_map($entity_save, EntityFormDisplay::loadMultiple()); array_map($entity_save, EntityFormDisplay::loadMultiple());
...@@ -31,8 +34,10 @@ function field_layout_install() { ...@@ -31,8 +34,10 @@ function field_layout_install() {
function field_layout_uninstall() { function field_layout_uninstall() {
// Reset each entity display to use the one-column layout to best approximate // Reset each entity display to use the one-column layout to best approximate
// the absence of layouts. // the absence of layouts.
$entity_save = function (EntityDisplayWithLayoutInterface $entity) { $entity_save = function (EntityDisplayInterface $entity) {
$entity->setLayoutId('layout_onecol')->save(); if ($entity instanceof EntityDisplayWithLayoutInterface) {
$entity->setLayoutId('layout_onecol')->save();
}
}; };
array_map($entity_save, EntityViewDisplay::loadMultiple()); array_map($entity_save, EntityViewDisplay::loadMultiple());
array_map($entity_save, EntityFormDisplay::loadMultiple()); array_map($entity_save, EntityFormDisplay::loadMultiple());
......
<?php
namespace Drupal\Tests\field_layout\Kernel;
use Drupal\Tests\layout_builder\Kernel\LayoutBuilderCompatibilityTestBase;
/**
* @group field_layout
*/
class FieldLayoutUninstallTest extends LayoutBuilderCompatibilityTestBase {
/**
* Ensures field layout can be uninstalled with layout builder enabled.
*/
public function testFieldLayoutUninstall() {
// Setup user schema so user hook uninstall hook doesn't break.
$this->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']);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment