commit 2db9acd7dead29d4d4a42e12158b2ca02f945253 Author: Francesco Placella Date: Sun Dec 14 00:12:23 2014 +0100 Reverted field module changes. diff --git a/core/modules/comment/src/Tests/CommentUninstallTest.php b/core/modules/comment/src/Tests/CommentUninstallTest.php index 35a532e..419932d 100644 --- a/core/modules/comment/src/Tests/CommentUninstallTest.php +++ b/core/modules/comment/src/Tests/CommentUninstallTest.php @@ -7,7 +7,6 @@ namespace Drupal\comment\Tests; -use Drupal\Core\Extension\ModuleUninstallValidatorException; use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; @@ -42,32 +41,28 @@ function testCommentUninstallWithField() { $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $this->assertNotNull($field_storage, 'The comment_body field exists.'); - // 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); - } + // 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.'); } + /** * 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('node', 'comment'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $this->assertNotNull($field_storage, 'The comment_body field exists.'); $field_storage->delete(); // Check that the field is now deleted. - $field_storage = FieldStorageConfig::loadByName('node', 'comment'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $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/field.module b/core/modules/field/field.module index 9264d31..143e8c5 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -118,6 +118,40 @@ function field_cron() { } /** + * Implements hook_system_info_alter(). + * + * Goes through a list of all modules that provide a field type and makes them + * required if there are any active fields of that type. + */ +function field_system_info_alter(&$info, Extension $file, $type) { + // It is not safe to call entity_load_multiple_by_properties() during + // maintenance mode. + if ($type == 'module' && !defined('MAINTENANCE_MODE')) { + $field_storages = entity_load_multiple_by_properties('field_storage_config', array('module' => $file->getName(), 'include_deleted' => TRUE)); + if ($field_storages) { + $info['required'] = TRUE; + + // Provide an explanation message (only mention pending deletions if there + // remains no actual, non-deleted fields) + $non_deleted = FALSE; + foreach ($field_storages as $field_storage) { + if (empty($field_storage->deleted)) { + $non_deleted = TRUE; + break; + } + } + if ($non_deleted) { + $explanation = t('Fields type(s) in use'); + } + else { + $explanation = t('Fields pending deletion'); + } + $info['explanation'] = $explanation; + } + } +} + +/** * Implements hook_entity_field_storage_info(). */ function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { diff --git a/core/modules/field/field.services.yml b/core/modules/field/field.services.yml deleted file mode 100644 index 7c33168..0000000 --- a/core/modules/field/field.services.yml +++ /dev/null @@ -1,6 +0,0 @@ -services: - field_module_uninstall_validator: - class: Drupal\field\ModuleUninstallValidator - tags: - - { name: module_install.uninstall_validator } - arguments: ['@entity.manager', '@string_translation'] diff --git a/core/modules/field/src/ModuleUninstallValidator.php b/core/modules/field/src/ModuleUninstallValidator.php deleted file mode 100644 index 90f917e..0000000 --- a/core/modules/field/src/ModuleUninstallValidator.php +++ /dev/null @@ -1,67 +0,0 @@ -entityManager = $entity_manager; - $this->stringTranslation = $string_translation; - } - - /** - * {@inheritdoc} - */ - public function validate($module_name) { - $reasons = array(); - - // It is not safe to call entity_load_multiple_by_properties() during - // maintenance mode. - if (!defined('MAINTENANCE_MODE')) { - $field_storages = $this->entityManager - ->getStorage('field_storage_config') - ->loadByProperties(array('module' => $module_name, 'include_deleted' => TRUE)); - - if ($field_storages) { - // Provide an explanation message (only mention pending deletions if there - // remains no actual, non-deleted fields) - $non_deleted = FALSE; - foreach ($field_storages as $field_storage) { - if (empty($field_storage->deleted)) { - $non_deleted = TRUE; - break; - } - } - - $reasons[] = $non_deleted ? $this->t('Fields type(s) in use') : $this->t('Fields pending deletion'); - } - } - - return $reasons; - } - -} diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index 947ba83..2b8f4c1 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/uninstall'); + $this->drupalGet('admin/modules'); $this->assertText('Fields type(s) in use'); $field_storage->delete(); - $this->drupalGet('admin/modules/uninstall'); + $this->drupalGet('admin/modules'); $this->assertText('Fields pending deletion'); $this->cronRun(); $this->assertNoText('Fields type(s) in use');