diff --cc core/modules/comment/comment.admin.inc index 2bfce3d,0418b1d..0000000 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@@ -376,7 -312,5 +376,7 @@@ function comment_confirm_delete_submit( // Clear the cache so an anonymous user sees that his comment was deleted. cache_invalidate_tags(array('content' => TRUE)); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); - $form_state['redirect'] = "node/{$comment->nid->target_id}"; ++ $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); + $uri = $entity->uri(); + $form_state['redirect'] = $uri['path']; } diff --cc core/modules/comment/comment.api.php index 7218931,793d9ad..0000000 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@@ -34,9 -34,7 +34,9 @@@ function hook_comment_presave(Drupal\co */ function hook_comment_insert(Drupal\comment\Comment $comment) { // Reindex the node when comments are added. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** @@@ -47,9 -45,7 +47,9 @@@ */ function hook_comment_update(Drupal\comment\Comment $comment) { // Reindex the node when comments are updated. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** diff --cc core/modules/comment/comment.module index b624f5f,14df557..0000000 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@@ -976,7 -945,7 +976,7 @@@ function comment_links(Comment $comment ); $links['comment-reply'] = array( 'title' => t('reply'), - 'href' => "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->value}/{$comment->field_name->value}/{$comment->id()}", - 'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}", ++ 'href' => "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->target_id}/{$comment->field_name->value}/{$comment->id()}", 'html' => TRUE, ); if ($comment->status->value == COMMENT_NOT_PUBLISHED) { @@@ -998,7 -967,7 +998,7 @@@ } $links['comment-reply'] = array( 'title' => t('reply'), - 'href' => "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->value}/{$comment->field_name->value}/{$comment->id()}", - 'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}", ++ 'href' => "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->target_id}/{$comment->field_name->value}/{$comment->id()}", 'html' => TRUE, ); } @@@ -1552,11 -1574,11 +1552,11 @@@ function comment_preview(Comment $comme $preview_build['comment_preview'] = $comment_build; } - if ($comment->pid->value) { + if ($comment->pid->target_id) { $build = array(); - $comment = $comment->pid->entity; - if ($comment && $comment->status->value == COMMENT_PUBLISHED) { - $build = comment_view($comment); + $parent = $comment->pid->entity; + if ($parent && $parent->status->value == COMMENT_PUBLISHED) { + $build = comment_view($parent); } } else { @@@ -1608,9 -1625,9 +1608,9 @@@ function comment_prepare_author(Commen */ function template_preprocess_comment(&$variables) { $comment = $variables['elements']['#comment']; - $comment_entity = entity_load($comment->entity_type->value, $comment->entity_id->value); - $node = $variables['elements']['#node']; ++ $comment_entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); $variables['comment'] = $comment; - $variables['node'] = $node; + $variables['comment_entity'] = $comment_entity; $account = comment_prepare_author($comment); $variables['author'] = theme('username', array('account' => $account)); @@@ -1705,11 -1722,10 +1705,11 @@@ $variables['attributes']['class'][] = 'by-anonymous'; } else { - if (($comment_entity instanceof EntityNG && !empty($comment_entity->uid->value) && $comment->uid->value == $comment_entity->uid->value) || - (!empty($comment_entity->uid) && $comment->uid->value == $comment_entity->uid)) { - if ($comment->uid->target_id == $variables['node']->uid) { - $variables['attributes']['class'][] = 'by-node-author'; ++ if (($comment_entity instanceof EntityNG && !empty($comment_entity->uid->target_id) && $comment->uid->target_id == $comment_entity->uid->target_id) || ++ (!empty($comment_entity->uid) && $comment->uid->target_id == $comment_entity->uid)) { + $variables['attributes']['class'][] = 'by-' . $comment_entity->entityType() . '-author'; } - if ($comment->uid->value == $variables['user']->uid) { + if ($comment->uid->target_id == $variables['user']->uid) { $variables['attributes']['class'][] = 'by-viewer'; } } diff --cc core/modules/comment/comment.pages.inc index 6cfa72e,da359a4..0000000 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@@ -69,14 -59,12 +69,14 @@@ function comment_reply(Drupal\Core\Enti if ($comment->status->value == COMMENT_PUBLISHED) { // If that comment exists, make sure that the current comment and the // parent comment both belong to the same parent node. - if ($comment->entity_id->value != $entity->id() || - if ($comment->nid->target_id != $node->nid) { - // Attempting to reply to a comment not belonging to the current nid. ++ if ($comment->entity_id->target_id != $entity->id() || + $comment->field_name->value != $field_name || + $comment->entity_type->value != $entity->entityType()) { + // Attempting to reply to a comment not belonging to the current entity. drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); - drupal_goto("node/$node->nid"); + drupal_goto($uri['path']); } - // Display the parent comment + // Display the parent comment. $build['comment_parent'] = comment_view($comment); } else { diff --cc core/modules/comment/comment.tokens.inc index d17f523,715b63d..0000000 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@@ -182,9 -175,9 +182,9 @@@ function comment_tokens($type, $tokens break; case 'parent': - if (!empty($comment->pid->value)) { - $parent = comment_load($comment->pid->value); + if (!empty($comment->pid->target_id)) { - $parent = comment_load($comment->pid->target_id); - $replacements[$original] = $sanitize ? filter_xss($parent->subject) : $parent->subject; ++ $parent = entity_load('comment', $comment->pid->target_id); + $replacements[$original] = $sanitize ? filter_xss($parent->subject->value) : $parent->subject->value; } break; @@@ -196,33 -189,17 +196,33 @@@ $replacements[$original] = format_date($comment->changed->value, 'medium', '', NULL, $langcode); break; - case 'node': - $node = $comment->nid->entity; - $title = $node->label(); + case 'entity': - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); ++ $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); + $title = $entity->label(); $replacements[$original] = $sanitize ? filter_xss($title) : $title; break; + + case 'node': + if ($comment->entity_type->value == 'node') { - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); ++ $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); + $title = $entity->label(); + $replacements[$original] = $sanitize ? filter_xss($title) : $title; + } + else { + $replacements[$original] = NULL; + } + break; } } // Chained token relationships. - if ($node_tokens = token_find_with_prefix($tokens, 'node')) { - $node = $comment->nid->entity; + if ($entity_tokens = token_find_with_prefix($tokens, 'entity')) { - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); ++ $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); + $replacements += token_generate($comment->entity_type->value, $entity_tokens, array($comment->entity_type->value => $entity), $options); + } + + if (($node_tokens = token_find_with_prefix($tokens, 'node')) && $comment->entity_type->value == 'node') { - $node = entity_load($comment->entity_type->value, $comment->entity_id->value); ++ $node = entity_load($comment->entity_type->value, $comment->entity_id->target_id); $replacements += token_generate('node', $node_tokens, array('node' => $node), $options); } diff --cc core/modules/comment/lib/Drupal/comment/CommentRenderController.php index 6e61777,dab8dc4..0000000 --- a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php @@@ -37,27 -37,22 +37,27 @@@ class CommentRenderController extends E parent::buildContent($entities, $displays, $view_mode, $langcode); - // Load all nodes of all comments at once. - $nids = array(); + // Load all entities of all comments at once. + $comment_entity_ids = array(); + $comment_entities = array(); foreach ($entities as $entity) { - $comment_entity_ids[$entity->entity_type->value][] = $entity->entity_id->value; - $nids[$entity->nid->target_id] = $entity->nid->target_id; ++ $comment_entity_ids[$entity->entity_type->value][] = $entity->entity_id->target_id; + } + // Load entities in bulk, this is more performant than using + // $comment->entity_id->value as we can load them in bulk per-type. + foreach ($comment_entity_ids as $entity_type => $entity_ids) { + $comment_entities[$entity_type] = entity_load_multiple($entity_type, $entity_ids); } - $nodes = node_load_multiple($nids); foreach ($entities as $entity) { - if (isset($comment_entities[$entity->entity_type->value][$entity->entity_id->value])) { - $comment_entity = $comment_entities[$entity->entity_type->value][$entity->entity_id->value]; - if (isset($nodes[$entity->nid->target_id])) { - $node = $nodes[$entity->nid->target_id]; ++ if (isset($comment_entities[$entity->entity_type->value][$entity->entity_id->target_id])) { ++ $comment_entity = $comment_entities[$entity->entity_type->value][$entity->entity_id->target_id]; } else { - throw new \InvalidArgumentException(t('Invalid node for comment.')); + throw new \InvalidArgumentException(t('Invalid entity for comment.')); } - $entity->content['#node'] = $node; - $entity->content['#theme'] = 'comment__node_' . $node->bundle(); + $entity->content['#entity'] = $entity; + $entity->content['#theme'] = 'comment__' . $entity->entity_type->value . '__' . $comment_entity->bundle() . '__' . $entity->field_name->value; $entity->content['links'] = array( '#theme' => 'links__comment', '#pre_render' => array('drupal_pre_render_links'), diff --cc core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 03db901,6851be0..0000000 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@@ -72,16 -91,10 +72,16 @@@ class CommentStorageController extends // is extended in a faulty manner. throw new LogicException('preSave is called again without calling postSave() or releaseThreadLock()'); } - if ($comment->pid->value == 0) { + if ($comment->pid->target_id == 0) { // This is a comment with no parent comment (depth 0): we start // by retrieving the maximum thread level. - $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid->target_id))->fetchField(); + $query = db_select('comment', 'c') - ->condition('entity_id', $comment->entity_id->value) ++ ->condition('entity_id', $comment->entity_id->target_id) + ->condition('field_name', $comment->field_name->value) + ->condition('entity_type', $comment->entity_type->value); + $query->addExpression('MAX(thread)', 'thread'); + $max = $query->execute() + ->fetchField(); // Strip the "/" from the end of the thread. $max = rtrim($max, '/'); // We need to get the value at the correct depth. @@@ -98,14 -112,10 +98,14 @@@ $parent->thread->value = (string) rtrim((string) $parent->thread->value, '/'); $prefix = $parent->thread->value . '.'; // Get the max value in *this* thread. - $max = db_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array( - ':thread' => $parent->thread->value . '.%', - ':nid' => $comment->nid->target_id, - ))->fetchField(); + $query = db_select('comment', 'c') - ->condition('entity_id', $comment->entity_id->value) ++ ->condition('entity_id', $comment->entity_id->target_id) + ->condition('field_name', $comment->field_name->value) + ->condition('entity_type', $comment->entity_type->value) + ->condition('thread', $parent->thread->value . '.%', 'LIKE'); + $query->addExpression('MAX(thread)', 'thread'); + $max = $query->execute() + ->fetchField(); if ($max == '') { // First child of this parent. As the other two cases do an @@@ -127,7 -137,7 +127,7 @@@ // has the lock, just move to the next integer. do { $thread = $prefix . comment_int_to_alphadecimal(++$n) . '/'; - } while (!lock()->acquire("comment:{$comment->entity_id->value}:{$comment->entity_type->value}:$thread")); - } while (!lock()->acquire("comment:{$comment->nid->target_id}:$thread")); ++ } while (!lock()->acquire("comment:{$comment->entity_id->target_id}:{$comment->entity_type->value}:$thread")); $this->threadLock = $thread; } if (empty($comment->created->value)) { @@@ -283,13 -274,14 +283,14 @@@ $properties['pid'] = array( 'label' => t('Parent ID'), 'description' => t('The parent comment ID if this is a reply to a comment.'), - 'type' => 'entityreference_field', - 'settings' => array('entity type' => 'comment'), + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'comment'), ); - $properties['nid'] = array( - 'label' => t('Node ID'), - 'description' => t('The ID of the node of which this comment is a reply.'), + $properties['entity_id'] = array( + 'label' => t('Entity ID'), + 'description' => t('The ID of the entity of which this comment is a reply.'), - 'type' => 'integer_field', + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'node'), 'required' => TRUE, ); $properties['langcode'] = array( diff --cc core/modules/comment/lib/Drupal/comment/FieldNewValue.php index 9734f4b,52875ca..0000000 --- a/core/modules/comment/lib/Drupal/comment/FieldNewValue.php +++ b/core/modules/comment/lib/Drupal/comment/FieldNewValue.php diff --cc core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index 200dc92,24a7931..0000000 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@@ -92,24 -92,13 +92,24 @@@ class CommentInterfaceTest extends Comm $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); $reply_loaded = comment_load($reply->id()); $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.'); - $this->assertEqual($comment->id(), $reply_loaded->pid->value, 'Pid of a reply to a comment is set correctly.'); + $this->assertEqual($comment->id(), $reply_loaded->pid->target_id, 'Pid of a reply to a comment is set correctly.'); - $this->assertEqual(rtrim($comment->thread->value, '/') . '.00/', $reply_loaded->thread->value, 'Thread of reply grows correctly.'); + // Check the thread of reply grows correctly. + $this->assertEqual(rtrim($comment->thread->value, '/') . '.00/', $reply_loaded->thread->value); - // Second reply to comment #3 creating comment #4. - $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id()); - $this->assertText($subject_text, 'Individual comment-reply subject found.'); - $this->assertText($comment_text, 'Individual comment-reply body found.'); + // Second reply to comment #2 creating comment #4. + $this->drupalGet('comment/reply/node/' . $this->node->nid . '/comment/' . $comment->id()); + $this->assertText($comment->subject->value, 'Individual comment-reply subject found.'); + $this->assertText($comment->comment_body->value, 'Individual comment-reply body found.'); + $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); + $reply_loaded = comment_load($reply->id()); + $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.'); + // Check the thread of second reply grows correctly. + $this->assertEqual(rtrim($comment->thread->value, '/') . '.01/', $reply_loaded->thread->value); + + // Reply to comment #4 creating comment #5. + $this->drupalGet('comment/reply/node/' . $this->node->nid . '/comment/' . $reply_loaded->id()); + $this->assertText($reply_loaded->subject->value, 'Individual comment-reply subject found.'); + $this->assertText($reply_loaded->comment_body->value, 'Individual comment-reply body found.'); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); $reply_loaded = comment_load($reply->id()); $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.'); diff --cc core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 956388e,6bcc992..0000000 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@@ -61,11 -61,11 +61,11 @@@ class CommentTokenReplaceTest extends C $tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options); $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created->value, 2, $language_interface->langcode); $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed->value, 2, $language_interface->langcode); - $tests['[comment:parent:cid]'] = $comment->pid->value; + $tests['[comment:parent:cid]'] = $comment->pid->target_id; $tests['[comment:parent:title]'] = check_plain($parent_comment->subject->value); - $tests['[comment:node:nid]'] = $comment->entity_id->value; - $tests['[comment:node:nid]'] = $comment->nid->target_id; ++ $tests['[comment:node:nid]'] = $comment->entity_id->target_id; $tests['[comment:node:title]'] = check_plain($node->title); - $tests['[comment:author:uid]'] = $comment->uid->value; + $tests['[comment:author:uid]'] = $comment->uid->target_id; $tests['[comment:author:name]'] = check_plain($this->admin_user->name); // Test to make sure that we generated something for each token. diff --cc core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php index d1383a1,3006f94..0000000 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php @@@ -72,22 -71,15 +72,22 @@@ class DefaultViewRecentComments extend // Add a node of the new content type. $node_data = array( 'type' => $content_type->type, + "comment[$language_not_specified][0][comment]" => COMMENT_OPEN ); + comment_add_default_comment_field('node', $content_type->type); $this->node = $this->drupalCreateNode($node_data); + views_invalidate_cache(); + // Create some comments and attach them to the created node. for ($i = 0; $i < $this->masterDisplayResults; $i++) { - $comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->type)); + $comment = entity_create('comment', array('field_name' => 'comment')); - $comment->uid->value = 0; + $comment->uid->target_id = 0; - $comment->nid->target_id = $this->node->nid; + $comment->entity_type->value = 'node'; + // Stagger the comments so the timestamp sorting works. + $comment->created->value = REQUEST_TIME - $i; - $comment->entity_id->value = $this->node->nid; ++ $comment->entity_id->target_id = $this->node->nid; $comment->subject->value = 'Test comment ' . $i; $comment->comment_body->value = 'Test body ' . $i; $comment->comment_body->format = 'full_html'; @@@ -115,7 -107,7 +115,7 @@@ ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['entity_id'] = $comment->entity_id->value; - $expected_result[$key]['nid'] = $comment->nid->target_id; ++ $expected_result[$key]['entity_id'] = $comment->entity_id->target_id; $expected_result[$key]['subject'] = $comment->subject->value; $expected_result[$key]['cid'] = $comment->id(); $expected_result[$key]['changed'] = $comment->changed->value; @@@ -147,7 -139,7 +147,7 @@@ ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['entity_id'] = $comment->entity_id->value; - $expected_result[$key]['nid'] = $comment->nid->target_id; ++ $expected_result[$key]['entity_id'] = $comment->entity_id->target_id; $expected_result[$key]['subject'] = $comment->subject->value; $expected_result[$key]['changed'] = $comment->changed->value; $expected_result[$key]['created'] = $comment->created->value; diff --cc core/modules/forum/forum.module index 04efecb,872eb95..0000000 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@@ -486,9 -486,7 +486,9 @@@ function forum_taxonomy_term_delete(Ter * comment_save() calls hook_comment_publish() for all published comments. */ function forum_comment_publish($comment) { - _forum_update_forum_index($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - _forum_update_forum_index($comment->entity_id->value); ++ _forum_update_forum_index($comment->entity_id->target_id); + } } /** @@@ -500,8 -498,8 +500,8 @@@ function forum_comment_update($comment) { // comment_save() calls hook_comment_publish() for all published comments, // so we need to handle all other values here. - if (!$comment->status->value) { - _forum_update_forum_index($comment->nid->target_id); + if (!$comment->status->value && $comment->entity_type->value == 'node') { - _forum_update_forum_index($comment->entity_id->value); ++ _forum_update_forum_index($comment->entity_id->target_id); } } @@@ -509,18 -507,14 +509,18 @@@ * Implements hook_comment_unpublish(). */ function forum_comment_unpublish($comment) { - _forum_update_forum_index($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - _forum_update_forum_index($comment->entity_id->value); ++ _forum_update_forum_index($comment->entity_id->target_id); + } } /** * Implements hook_comment_delete(). */ function forum_comment_delete($comment) { - _forum_update_forum_index($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - _forum_update_forum_index($comment->entity_id->value); ++ _forum_update_forum_index($comment->entity_id->target_id); + } } /** diff --cc core/modules/rdf/rdf.module index a6e5e11,255fc97..0000000 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@@ -417,11 -417,9 +417,11 @@@ function rdf_comment_load($comments) // isn't needed until rdf_preprocess_comment() is called, but set it here // to optimize performance for websites that implement an entity cache. $comment->rdf_data['date'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created->value); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); - $comment->rdf_data['nid_uri'] = url('node/' . $comment->nid->target_id); - if ($comment->pid->target_id) { ++ $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); + $uri = $entity->uri(); + $comment->rdf_data['entity_uri'] = url($uri['path'], $uri['options']); + if ($comment->pid->value) { - $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid->value, array('fragment' => 'comment-' . $comment->pid->value)); + $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid->target_id, array('fragment' => 'comment-' . $comment->pid->target_id)); } } } @@@ -741,18 -735,18 +741,18 @@@ function rdf_preprocess_comment(&$varia $variables['title_attributes']['datatype'] = ''; } - // Annotates the parent relationship between the current comment and the node - // it belongs to. If available, the parent comment is also annotated. + // Annotates the parent relationship between the current comment and the + // entity it belongs to. If available, the parent comment is also annotated. if (!empty($comment->rdf_mapping['pid'])) { - // Adds the relation to the parent node. - $parent_node_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; - // The parent node URI is precomputed as part of the rdf_data so that it can + // Adds the relation to the parent entity. + $parent_entity_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; + // The parent entity URI is precomputed as part of the rdf_data so that it can // be cached as part of the entity. - $parent_node_attributes['resource'] = $comment->rdf_data['nid_uri']; - $variables['rdf_metadata_attributes'][] = $parent_node_attributes; + $parent_entity_attributes['resource'] = $comment->rdf_data['entity_uri']; + $variables['rdf_metadata_attributes'][] = $parent_entity_attributes; // Adds the relation to parent comment, if it exists. - if ($comment->pid->value != 0) { + if ($comment->pid->target_id != 0) { $parent_comment_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; // The parent comment URI is precomputed as part of the rdf_data so that // it can be cached as part of the entity. diff --cc core/modules/search/search.module index de26282,5c67997..0000000 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@@ -815,9 -810,7 +815,9 @@@ function search_node_update(Node $node */ function search_comment_insert($comment) { // Reindex the node when comments are added. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** @@@ -825,9 -818,7 +825,9 @@@ */ function search_comment_update($comment) { // Reindex the node when comments are changed. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** @@@ -835,9 -826,7 +835,9 @@@ */ function search_comment_delete($comment) { // Reindex the node when comments are deleted. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** @@@ -845,9 -834,7 +845,9 @@@ */ function search_comment_publish($comment) { // Reindex the node when comments are published. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** @@@ -855,9 -842,7 +855,9 @@@ */ function search_comment_unpublish($comment) { // Reindex the node when comments are unpublished. - search_touch_node($comment->nid->target_id); + if ($comment->entity_type->value == 'node') { - search_touch_node($comment->entity_id->value); ++ search_touch_node($comment->entity_id->target_id); + } } /** diff --cc core/modules/system/system.module index 4f1d49f,322e416..0000000 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module diff --cc core/modules/tracker/tracker.module index 8280f3d,30a0dbb..0000000 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@@ -231,8 -229,8 +231,8 @@@ function tracker_node_predelete(Node $n function tracker_comment_update($comment) { // comment_save() calls hook_comment_publish() for all published comments // so we need to handle all other values here. - if ($comment->status->value != COMMENT_PUBLISHED) { - _tracker_remove($comment->nid->target_id, $comment->uid->target_id, $comment->changed->value); + if ($comment->status->value != COMMENT_PUBLISHED && $comment->entity_type->value == 'node') { - _tracker_remove($comment->entity_id->value, $comment->uid->value, $comment->changed->value); ++ _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); } } @@@ -243,27 -241,21 +243,27 @@@ * comment_save() calls hook_comment_publish() for all published comments. */ function tracker_comment_publish($comment) { - _tracker_add($comment->nid->target_id, $comment->uid->target_id, $comment->changed->value); + if ($comment->entity_type->value == 'node') { - _tracker_add($comment->entity_id->value, $comment->uid->value, $comment->changed->value); ++ _tracker_add($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); + } } /** * Implements hook_comment_unpublish(). */ function tracker_comment_unpublish($comment) { - _tracker_remove($comment->nid->target_id, $comment->uid->target_id, $comment->changed->value); + if ($comment->entity_type->value == 'node') { - _tracker_remove($comment->entity_id->value, $comment->uid->value, $comment->changed->value); ++ _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); + } } /** * Implements hook_comment_delete(). */ function tracker_comment_delete($comment) { - _tracker_remove($comment->nid->target_id, $comment->uid->target_id, $comment->changed->value); + if ($comment->entity_type->value == 'node') { - _tracker_remove($comment->entity_id->value, $comment->uid->value, $comment->changed->value); ++ _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); + } } /** diff --cc core/modules/views/config/views.view.comments_recent.yml index d775ad1,6560938..0000000 --- a/core/modules/views/config/views.view.comments_recent.yml +++ b/core/modules/views/config/views.view.comments_recent.yml @@@ -30,11 -30,11 +30,12 @@@ display options: items_per_page: 5 relationships: - nid: - id: nid + node: + field: node + id: node + required: '1' table: comment - field: nid + plugin_id: standard fields: subject: id: subject @@@ -59,8 -62,9 +63,9 @@@ id: status_extra table: node field: status_extra - relationship: nid + relationship: node group: 0 + plugin_id: node_status style: type: html_list row: @@@ -85,9 -89,10 +90,10 @@@ id: title table: node field: title - relationship: nid + relationship: node label: 'Reply to' link_to_node: 1 + plugin_id: node timestamp: id: timestamp table: comment diff --cc core/modules/views/tests/views_test_config/test_views/views.view.test_destroy.yml index 4d1356a,f7df985..0000000 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_destroy.yml +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_destroy.yml @@@ -116,29 -131,34 +131,34 @@@ display query: type: views_query relationships: - cid: - field: cid - id: cid + comment_cid: + field: comment_cid + id: comment_cid table: node + plugin_id: standard pid: field: pid id: pid table: comment - relationship: cid + relationship: comment_cid + plugin_id: standard uid: field: uid id: uid table: comment - relationship: cid + relationship: comment_cid + plugin_id: standard sorts: last_comment_name: field: last_comment_name id: last_comment_name - table: node_comment_statistics - plugin_id: comment_ncs_last_comment_name + table: comment_entity_statistics ++ plugin_id: comment_ces_last_comment_name last_comment_timestamp: field: last_comment_timestamp id: last_comment_timestamp - table: node_comment_statistics + table: comment_entity_statistics + plugin_id: date style: type: default row: diff --cc core/modules/views/tests/views_test_config/test_views/views.view.test_field_get_entity.yml index db9db1e,2951397..0000000 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_field_get_entity.yml +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_field_get_entity.yml @@@ -20,7 -21,8 +21,8 @@@ display field: nid id: nid table: node - relationship: nid + relationship: node + plugin_id: node uid: field: uid id: uid @@@ -35,20 -38,22 +38,22 @@@ query: type: views_query relationships: - nid: - field: nid - id: nid + node: + field: node + id: node required: '1' table: comment + plugin_id: standard uid: admin_label: '' field: uid group_type: group id: uid label: author - relationship: nid + relationship: node required: '0' table: node + plugin_id: standard sorts: { } style: type: default diff --cc core/modules/views/tests/views_test_config/test_views/views.view.test_handler_relationships.yml index 94fc786,efa8ccc..0000000 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_handler_relationships.yml +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_handler_relationships.yml @@@ -10,16 -10,19 +10,19 @@@ display id: title table: node field: title + plugin_id: node relationships: - cid: - id: cid + comment_cid: + id: comment_cid table: node - field: cid + field: comment_cid + plugin_id: standard nid: id: nid table: comment - field: nid - relationship: cid + field: node + relationship: comment_cid + plugin_id: standard display_plugin: default display_title: Master id: default diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index ff7d2d3..dbddcb1 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -39,8 +39,8 @@ public function form(array $form, array &$form_state, EntityInterface $comment) // If not replying to a comment, use our dedicated page callback for new // comments on entities. - if (!$comment->id() && empty($comment->pid->value)) { - $form['#action'] = url('comment/reply/' . $comment->entity_type->value . '/' . $comment->entity_id->value . '/' . $comment->field_name->value); + if (!$comment->id() && empty($comment->pid->target_id)) { + $form['#action'] = url('comment/reply/' . $comment->entity_type->value . '/' . $comment->entity_id->target_id . '/' . $comment->field_name->value); } if (isset($form_state['comment_preview'])) { @@ -55,7 +55,6 @@ public function form(array $form, array &$form_state, EntityInterface $comment) $form['author'] += array( '#type' => 'details', '#title' => t('Administration'), - '#collapsible' => TRUE, '#collapsed' => TRUE, ); } @@ -78,38 +77,23 @@ public function form(array $form, array &$form_state, EntityInterface $comment) } // Add the author name field depending on the current user. + $form['author']['name'] = array( + '#type' => 'textfield', + '#title' => t('Your name'), + '#default_value' => $author, + '#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT), + '#maxlength' => 60, + '#size' => 30, + ); if ($is_admin) { - $form['author']['name'] = array( - '#type' => 'textfield', - '#title' => t('Authored by'), - '#default_value' => $author, - '#maxlength' => 60, - '#size' => 30, - '#description' => t('Leave blank for %anonymous.', array('%anonymous' => config('user.settings')->get('anonymous'))), - '#autocomplete_path' => 'user/autocomplete', - ); + $form['author']['name']['#title'] = t('Authored by'); + $form['author']['name']['#description'] = t('Leave blank for %anonymous.', array('%anonymous' => config('user.settings')->get('anonymous'))); + $form['author']['name']['#autocomplete_path'] = 'user/autocomplete'; } elseif ($user->uid) { - $form['author']['_author'] = array( - '#type' => 'item', - '#title' => t('Your name'), - '#markup' => theme('username', array('account' => $user)), - ); - - $form['author']['name'] = array( - '#type' => 'value', - '#value' => $author, - ); - } - else { - $form['author']['name'] = array( - '#type' => 'textfield', - '#title' => t('Your name'), - '#default_value' => $author, - '#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT), - '#maxlength' => 60, - '#size' => 30, - ); + $form['author']['name']['#type'] = 'item'; + $form['author']['name']['#value'] = $form['author']['name']['#default_value']; + $form['author']['name']['#markup'] = theme('username', array('account' => $user)); } // Add author e-mail and homepage fields depending on the current user. @@ -165,7 +149,7 @@ public function form(array $form, array &$form_state, EntityInterface $comment) // Used for conditional validation of author fields. $form['is_anonymous'] = array( '#type' => 'value', - '#value' => ($comment->id() ? !$comment->uid->value : !$user->uid), + '#value' => ($comment->id() ? !$comment->uid->target_id : !$user->uid), ); // Make the comment inherit the current content language unless specifically @@ -177,7 +161,8 @@ public function form(array $form, array &$form_state, EntityInterface $comment) // Add internal comment properties. foreach (array('cid', 'pid', 'entity_id', 'entity_type', 'field_name', 'uid', 'langcode') as $key) { - $form[$key] = array('#type' => 'value', '#value' => $comment->$key->value); + $key_name = key($comment->$key->offsetGet(0)->getProperties()); + $form[$key] = array('#type' => 'value', '#value' => $comment->$key->{$key_name}); } return parent::form($form, $form_state, $comment); @@ -278,7 +263,7 @@ public function submit(array $form, array &$form_state) { // @todo Too fragile. Should be prepared and stored in comment_form() // already. if (!$comment->is_anonymous && !empty($comment->name->value) && ($account = user_load_by_name($comment->name->value))) { - $comment->uid->value = $account->uid; + $comment->uid->target_id = $account->uid; } // If the comment was posted by an anonymous user and no author name was // required, use "Anonymous" by default.