diff --git a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php index 4777939..6f8fc20 100644 --- a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php +++ b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Field; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityStorageInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -47,7 +46,7 @@ public function validate($module_name) { // to be able to uninstall them anyway. We also skip the Field module as // it implements field purging. // See \Drupal\Core\Entity\ContentUninstallValidator. - if ($entity_type->getProvider() != $module_name && $entity_type instanceof FieldableEntityInterface) { + if ($entity_type->getProvider() != $module_name && $entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { foreach ($this->entityManager->getFieldStorageDefinitions($entity_type_id) as $storage_definition) { if ($module_name != 'field' && $storage_definition->getProvider() == $module_name) { $storage = $this->entityManager->getStorage($entity_type_id); diff --git a/core/modules/comment/src/Tests/CommentUninstallTest.php b/core/modules/comment/src/Tests/CommentUninstallTest.php index 419932d..35a532e 100644 --- a/core/modules/comment/src/Tests/CommentUninstallTest.php +++ b/core/modules/comment/src/Tests/CommentUninstallTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Extension\ModuleUninstallValidatorException; use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; @@ -41,28 +42,32 @@ function testCommentUninstallWithField() { $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $this->assertNotNull($field_storage, 'The comment_body field exists.'); - // Uninstall the comment module which should trigger field deletion. - $this->container->get('module_installer')->uninstall(array('comment')); - - // Check that the field is now deleted. - $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); - $this->assertNull($field_storage, 'The comment_body field has been deleted.'); + // Uninstall the comment module which should not trigger field deletion. + $message = 'The comment_body field has not been deleted.'; + try { + $this->container->get('module_installer')->uninstall(array('comment')); + $this->fail($message); + } + catch (ModuleUninstallValidatorException $e) { + $this->pass($message); + } } - /** * Tests if uninstallation succeeds if the field has been deleted beforehand. */ function testCommentUninstallWithoutField() { // Manually delete the comment_body field before module uninstallation. - $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $field_storage = FieldStorageConfig::loadByName('node', 'comment'); $this->assertNotNull($field_storage, 'The comment_body field exists.'); $field_storage->delete(); // Check that the field is now deleted. - $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $field_storage = FieldStorageConfig::loadByName('node', 'comment'); $this->assertNull($field_storage, 'The comment_body field has been deleted.'); + field_purge_batch(1); + // Ensure that uninstallation succeeds even if the field has already been // deleted manually beforehand. $this->container->get('module_installer')->uninstall(array('comment')); diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index 2b8f4c1..947ba83 100644 --- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php @@ -88,10 +88,10 @@ function testReEnabledField() { // for it's fields. $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules')); $this->drupalLogin($admin_user); - $this->drupalGet('admin/modules'); + $this->drupalGet('admin/modules/uninstall'); $this->assertText('Fields type(s) in use'); $field_storage->delete(); - $this->drupalGet('admin/modules'); + $this->drupalGet('admin/modules/uninstall'); $this->assertText('Fields pending deletion'); $this->cronRun(); $this->assertNoText('Fields type(s) in use');