diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index 36f70ca..e94bc0d 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -170,9 +170,9 @@ public function addEntityField($comment_type_id) { 'handler' => 'default:' . $comment_type->getTargetEntityTypeId(), ], 'module' => 'entity_reference', - 'locked' => FALSE, + 'locked' => TRUE, 'cardinality' => 1, - 'translatable' => TRUE, + 'translatable' => FALSE, 'indexes' => [], 'persist_with_no_fields' => TRUE, ]); diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php index b6a5c04..0148889 100644 --- a/core/modules/comment/src/CommentViewBuilder.php +++ b/core/modules/comment/src/CommentViewBuilder.php @@ -67,6 +67,9 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco /** @var \Drupal\comment\CommentInterface $entity */ // Store a threading field setting to use later in self::buildComponents(). + if (!$entity->getCommentedEntity()) { + debug(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); + } $build['#comment_threaded'] = $entity->getCommentedEntity() ->getFieldDefinition($entity->getFieldName()) ->getSetting('default_mode') === CommentManagerInterface::COMMENT_MODE_THREADED; diff --git a/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php b/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php index f24e39c..dc25992 100644 --- a/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php +++ b/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php @@ -56,6 +56,7 @@ function setUp() { 'uid' => $this->loggedInUser->id(), 'commented_node' => $this->nodeUserCommented->id(), 'entity_type' => 'node', + 'comment_type' => 'comment', 'field_name' => 'comment', 'cid' => '', 'pid' => '', diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml index f005b0b..c318345 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml @@ -56,16 +56,7 @@ display: type: 'entity:comment' options: view_mode: default - relationships: - commented_node: - id: commented_node - table: comment__commented_node - field: commented_node - relationship: none - group_type: group - admin_label: 'Content' - required: true - plugin_id: standard + relationships: { } fields: subject: id: subject diff --git a/core/modules/forum/config/optional/field.field.comment.comment_forum.commented_node.yml b/core/modules/forum/config/optional/field.field.comment.comment_forum.commented_node.yml new file mode 100644 index 0000000..70d9832 --- /dev/null +++ b/core/modules/forum/config/optional/field.field.comment.comment_forum.commented_node.yml @@ -0,0 +1,24 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment_forum + - field.storage.comment.commented_node + module: + - entity_reference +id: comment.comment_forum.commented_node +field_name: commented_node +entity_type: comment +bundle: comment_forum +label: Commented Node +description: '' +required: true +translatable: false +default_value: { } +default_value_callback: '' +settings: + target_type: node + handler: 'default:node' + handler_settings: { } +third_party_settings: { } +field_type: entity_reference diff --git a/core/modules/forum/config/optional/field.storage.comment.commented_node.yml b/core/modules/forum/config/optional/field.storage.comment.commented_node.yml new file mode 100644 index 0000000..2b34306 --- /dev/null +++ b/core/modules/forum/config/optional/field.storage.comment.commented_node.yml @@ -0,0 +1,18 @@ +langcode: en +status: true +dependencies: + module: + - comment + - entity_reference +id: comment.commented_node +field_name: commented_node +entity_type: comment +type: entity_reference +settings: + target_type: node +module: entity_reference +locked: true +cardinality: 1 +translatable: false +indexes: { } +persist_with_no_fields: true diff --git a/core/modules/forum/src/ForumIndexStorage.php b/core/modules/forum/src/ForumIndexStorage.php index b50f29b..a19cd60 100644 --- a/core/modules/forum/src/ForumIndexStorage.php +++ b/core/modules/forum/src/ForumIndexStorage.php @@ -9,6 +9,7 @@ use Drupal\comment\CommentInterface; use Drupal\Core\Database\Connection; use Drupal\node\NodeInterface; +use Drupal\field\Entity\FieldStorageConfig; /** * Handles CRUD operations to {forum_index} table. @@ -96,14 +97,18 @@ public function update(NodeInterface $node) { */ public function updateIndex(NodeInterface $node) { $nid = $node->id(); - $count = $this->database->query("SELECT COUNT(cid) FROM {comment_field_data} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1", array( + $field_storage = FieldStorageConfig::loadByName('comment', 'commented_node'); + $table_mapping = \Drupal::entityManager()->getStorage('comment')->getTableMapping(); + $comment_entity_table = $table_mapping->getDedicatedDataTableName($field_storage); + $target_id_column = $table_mapping->getFieldColumnName($field_storage, 'target_id'); + $count = $this->database->query("SELECT COUNT(cid) FROM {comment_field_data} c INNER JOIN {" . $comment_entity_table . "} ce ON c.cid = ce.entity_id AND ce.deleted = 0 INNER JOIN {forum_index} i ON ce." . $target_id_column . " = i.nid WHERE ce." . $target_id_column . " = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1", array( ':nid' => $nid, ':status' => CommentInterface::PUBLISHED, ))->fetchField(); if ($count > 0) { // Comments exist. - $last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment_field_data} WHERE entity_id = :nid AND field_name = 'comment_forum' AND entity_type = 'node' AND status = :status AND default_langcode = 1 ORDER BY cid DESC", 0, 1, array( + $last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment_field_data} c INNER JOIN {" . $comment_entity_table . "} ce ON c.cid = ce.entity_id AND ce.deleted = 0 WHERE ce." . $target_id_column . " = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1 ORDER BY c.cid DESC", 0, 1, array( ':nid' => $nid, ':status' => CommentInterface::PUBLISHED, ))->fetchObject(); diff --git a/core/modules/forum/src/Tests/ForumBlockTest.php b/core/modules/forum/src/Tests/ForumBlockTest.php index 78e1c44..e883ba0 100644 --- a/core/modules/forum/src/Tests/ForumBlockTest.php +++ b/core/modules/forum/src/Tests/ForumBlockTest.php @@ -98,7 +98,7 @@ public function testActiveForumTopicsBlock() { $node = $this->drupalGetNodeByTitle($topics[$index]); $date->modify('+1 minute'); $comment = entity_create('comment', array( - 'entity_id' => $node->id(), + 'commented_node' => $node->id(), 'field_name' => 'comment_forum', 'entity_type' => 'node', 'node_type' => 'node_type_' . $node->bundle(), diff --git a/core/modules/forum/src/Tests/ForumUninstallTest.php b/core/modules/forum/src/Tests/ForumUninstallTest.php index db7c091..849fb6f 100644 --- a/core/modules/forum/src/Tests/ForumUninstallTest.php +++ b/core/modules/forum/src/Tests/ForumUninstallTest.php @@ -59,7 +59,7 @@ public function testForumUninstallWithField() { // Create at least one comment against the forum node. $comment = entity_create('comment', array( - 'entity_id' => $node->nid->value, + 'commented_node' => $node->nid->value, 'entity_type' => 'node', 'field_name' => 'comment_forum', 'pid' => 0, diff --git a/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php b/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php index de169f6..5edb1d5 100644 --- a/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php +++ b/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php @@ -63,9 +63,9 @@ public function testForumIntegration() { $comments = array(); foreach ($nodes as $index => $node) { for ($i = 0; $i <= $index; $i++) { - $comment = $comment_storage->create(array('entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum')); + $comment = $comment_storage->create(array('entity_type' => 'node', 'commented_node' => $node->id(), 'field_name' => 'comment_forum')); $comment->save(); - $comments[$comment->get('entity_id')->target_id][$comment->id()] = $comment; + $comments[$comment->get('commented_node')->target_id][$comment->id()] = $comment; } } diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php index 9fb1014..8deb9c6 100644 --- a/core/modules/hal/src/Tests/EntityTest.php +++ b/core/modules/hal/src/Tests/EntityTest.php @@ -174,7 +174,7 @@ public function testComment() { 'value' => $this->randomMachineName(), 'format' => NULL, ], - 'entity_id' => $node->id(), + 'entity_node' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment', )); @@ -187,7 +187,7 @@ public function testComment() { 'value' => $this->randomMachineName(), 'format' => NULL, ], - 'entity_id' => $node->id(), + 'commented_node' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => $parent_comment->id(), diff --git a/core/modules/migrate_drupal/config/optional/migrate.migration.d6_comment.yml b/core/modules/migrate_drupal/config/optional/migrate.migration.d6_comment.yml index 94fb020..93ff138 100644 --- a/core/modules/migrate_drupal/config/optional/migrate.migration.d6_comment.yml +++ b/core/modules/migrate_drupal/config/optional/migrate.migration.d6_comment.yml @@ -12,7 +12,7 @@ process: plugin: migration migration: d6_comment source: pid - entity_id: nid + 'commented_node/target_id': nid entity_type: 'constants/entity_type' # field_name & comment_type is calculated in # \Drupal\migrate_drupal\Plugin\migrate\source\d6\Comment::prepareRow() diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php index 29a9fdf..a04cc41 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php @@ -22,7 +22,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { use CommentTestTrait; - static $modules = array('node', 'comment', 'text', 'filter'); + static $modules = array('node', 'comment', 'text', 'filter', 'entity_reference'); /** * {@inheritdoc} diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTypeTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTypeTest.php index 6a4560b..4c16379 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTypeTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTypeTest.php @@ -18,7 +18,7 @@ */ class MigrateCommentTypeTest extends MigrateDrupal6TestBase { - static $modules = array('node', 'comment', 'text', 'filter'); + static $modules = array('node', 'comment', 'text', 'filter', 'entity_reference'); /** * {@inheritdoc} diff --git a/core/profiles/standard/config/install/field.field.comment.comment.commented_node.yml b/core/profiles/standard/config/install/field.field.comment.comment.commented_node.yml index 3370b3d..dac86cd 100644 --- a/core/profiles/standard/config/install/field.field.comment.comment.commented_node.yml +++ b/core/profiles/standard/config/install/field.field.comment.comment.commented_node.yml @@ -13,17 +13,12 @@ bundle: comment label: Commented Node description: '' required: true -translatable: true +translatable: false default_value: { } default_value_callback: '' settings: + target_type: node handler: 'default:node' - handler_settings: - target_bundles: - page: page - article: article - sort: - field: _none - auto_create: true + handler_settings: { } third_party_settings: { } field_type: entity_reference diff --git a/core/profiles/standard/config/install/field.storage.comment.commented_node.yml b/core/profiles/standard/config/install/field.storage.comment.commented_node.yml index d98d188..2b34306 100644 --- a/core/profiles/standard/config/install/field.storage.comment.commented_node.yml +++ b/core/profiles/standard/config/install/field.storage.comment.commented_node.yml @@ -11,8 +11,8 @@ type: entity_reference settings: target_type: node module: entity_reference -locked: false +locked: true cardinality: 1 -translatable: true +translatable: false indexes: { } persist_with_no_fields: true