From 4a808340cb409b0aed4daa703cc3a2973853c9e9 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 11 Dec 2013 10:59:20 +0000 Subject: [PATCH] Issue #1966448 by marthinal, larowlan, codeyourdream: comment_entity_load() breaks after disabling the Forum module. --- core/modules/comment/comment.module | 5 +++ .../Drupal/forum/Tests/ForumUninstallTest.php | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index d6b95e8fc5a..fa5caee9bba 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -912,6 +912,11 @@ function comment_entity_load($entities, $entity_type) { foreach ($result as $record) { $parts = explode('__', $record->field_id, 2); list(, $field_name) = $parts; + + // Skip fields that entity does not have. + if (!$entities[$record->entity_id]->hasField($field_name)) { + continue; + } $comment_statistics = $entities[$record->entity_id]->get($field_name); $comment_statistics->cid = $record->cid; $comment_statistics->last_comment_timestamp = $record->last_comment_timestamp; diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php index 7243fa6b14c..d1f0e65c1fb 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -37,9 +37,48 @@ class ForumUninstallTest extends WebTestBase { $field = field_info_field('node', 'taxonomy_forums'); $this->assertNotNull($field, 'The taxonomy_forums field exists.'); + // Create a taxonomy term. + $term = entity_create('taxonomy_term', array( + 'name' => t('A term'), + 'langcode' => language_default()->id, + 'description' => '', + 'parent' => array(0), + 'vid' => 'forums', + 'forum_container' => 0, + )); + $term->save(); + + // Create a forum node. + $node = $this->drupalCreateNode(array( + 'title' => 'A forum post', + 'type' => 'forum', + 'taxonomy_forums' => array(array('target_id' => $term->id())), + )); + + // Create at least one comment against the forum node. + $comment = entity_create('comment', array( + 'entity_id' => $node->nid->value, + 'entity_type' => 'node', + 'field_name' => 'comment_forum', + 'pid' => 0, + 'uid' => 0, + 'status' => COMMENT_PUBLISHED, + 'subject' => $this->randomName(), + 'hostname' => '127.0.0.1', + )); + $comment->save(); + // Uninstall the forum module which should trigger field deletion. $this->container->get('module_handler')->uninstall(array('forum')); + // We want to test the handling of removing the forum comment field, so we + // ensure there is at least one other comment field attached to a node type + // so that comment_entity_load() runs for nodes. + \Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'another_comment_field', COMMENT_OPEN); + + $this->drupalGet('node/' . $node->nid->value); + $this->assertResponse(200); + // Check that the field is now deleted. $field = field_info_field('node', 'taxonomy_forums'); $this->assertNull($field, 'The taxonomy_forums field has been deleted.');