diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 8822f4b..0331d63 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Language\Language; +use Drupal\comment\Plugin\field\field_type\CommentItem; /** * Implements hook_uninstall(). @@ -586,6 +587,15 @@ function comment_update_8006(&$sandbox) { // Increment index. $index++; } + // Comment module may be disabled so we will need to inject the schema to + // avoid attempting to create a Field of an unknown type. + if (!Drupal::moduleHandler()->moduleExists('comment')) { + // We can't use the autoloader because the comment namespace isn't + // registered. + // @todo Remove once https://drupal.org/node/1199946 is in. + require_once __DIR__ . '/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php'; + $field['schema'] = CommentItem::schema(); + } _update_8003_field_create_field($field); if (Drupal::config("field.instance.node.$node_type." . $field['id'])->isNew()) { diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php index 6f9ad12..b3ac601 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Annotation\FieldType; +use Drupal\Core\Entity\Field\PrepareCacheInterface; use Drupal\field\Plugin\Core\Entity\Field; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; @@ -32,7 +33,7 @@ * default_formatter = "comment_default" * ) */ -class CommentItem extends ConfigFieldItemBase { +class CommentItem extends ConfigFieldItemBase implements PrepareCacheInterface { /** * Definitions of the contained properties. @@ -58,7 +59,7 @@ public function getPropertyDefinitions() { /** * {@inheritdoc} */ - public static function schema(Field $field) { + public static function schema(Field $field = NULL) { return array( 'columns' => array( 'status' => array( @@ -160,4 +161,9 @@ public function isEmpty() { return FALSE; } + /** + * {@inheritdoc} + */ + public function prepareCache() {} + } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index 96c5e6f..a4020f7 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -69,8 +69,16 @@ function testCommentEnable() { // Drop default comment field added in CommentTestBase::setup(). entity_load('field_entity', 'comment')->delete(); - $this->cronRun(); - $this->cronRun(); + if ($field = field_info_field('comment_node_forum')) { + $field->delete(); + } + + // Purge field data now to allow comment module to be disabled once the + // field has been deleted. + field_purge_batch(10); + // Call again as field_purge_batch() won't remove both the instances and + // field in a single pass. + field_purge_batch(10); // Disable the comment module. $edit = array(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index eb98602..44ed59a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -190,10 +190,7 @@ function testUninstallDependents() { $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall')); $this->drupalPost(NULL, NULL, t('Uninstall')); $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.'); - // Delete comment field to allow disabling of the comment module. - entity_load('field_entity', 'comment_node_forum')->delete(); - // Purge comment field storage data. - field_purge_batch(10); + // Disable the comment module. $edit = array('modules[Core][comment][enable]' => FALSE); $this->drupalPost('admin/modules', $edit, t('Save configuration'));