diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index b9d34a6..0418b1d 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -124,7 +124,7 @@ function comment_admin_overview($form, &$form_state, $arg) { 'data' => array( '#type' => 'link', '#title' => $node_title, - '#href' => 'node/' . $comment->nid->value, + '#href' => 'node/' . $comment->nid->target_id, ), ), 'changed' => format_date($comment->changed->value, 'short'), @@ -293,7 +293,7 @@ function comment_confirm_delete($form, &$form_state, Comment $comment) { return confirm_form( $form, t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject->value)), - 'node/' . $comment->nid->value, + 'node/' . $comment->nid->target_id, t('Any replies to this comment will be lost. This action cannot be undone.'), t('Delete'), t('Cancel'), @@ -312,5 +312,5 @@ function comment_confirm_delete_submit($form, &$form_state) { // Clear the cache so an anonymous user sees that his comment was deleted. cache_invalidate_tags(array('content' => TRUE)); - $form_state['redirect'] = "node/{$comment->nid->value}"; + $form_state['redirect'] = "node/{$comment->nid->target_id}"; } diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index cb4133d..793d9ad 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -34,7 +34,7 @@ function hook_comment_presave(Drupal\comment\Comment $comment) { */ function hook_comment_insert(Drupal\comment\Comment $comment) { // Reindex the node when comments are added. - search_touch_node($comment->nid->value); + search_touch_node($comment->nid->target_id); } /** @@ -45,7 +45,7 @@ function hook_comment_insert(Drupal\comment\Comment $comment) { */ function hook_comment_update(Drupal\comment\Comment $comment) { // Reindex the node when comments are updated. - search_touch_node($comment->nid->value); + search_touch_node($comment->nid->target_id); } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9cb4ebf..8730716 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -934,7 +934,7 @@ function comment_links(Comment $comment, Node $node) { ); $links['comment-reply'] = array( 'title' => t('reply'), - 'href' => "comment/reply/{$comment->nid->value}/{$comment->id()}", + 'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}", 'html' => TRUE, ); if ($comment->status->value == COMMENT_NOT_PUBLISHED) { @@ -956,7 +956,7 @@ function comment_links(Comment $comment, Node $node) { } $links['comment-reply'] = array( 'title' => t('reply'), - 'href' => "comment/reply/{$comment->nid->value}/{$comment->id()}", + 'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}", 'html' => TRUE, ); } @@ -1311,7 +1311,7 @@ function comment_user_cancel($edit, $account, $method) { case 'user_cancel_reassign': $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid)); foreach ($comments as $comment) { - $comment->uid->value = 0; + $comment->uid->target_id = 0; comment_save($comment); } break; @@ -1346,7 +1346,7 @@ function comment_access($op, Comment $comment) { global $user; if ($op == 'edit') { - return ($user->uid && $user->uid == $comment->uid->value && $comment->status->value == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments'); + return ($user->uid && $user->uid == $comment->uid->target_id && $comment->status->value == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments'); } } @@ -1549,7 +1549,7 @@ function comment_preview(Comment $comment) { } if (!empty($account->uid)) { - $comment->uid->value = $account->uid; + $comment->uid->target_id = $account->uid; $comment->name->value = check_plain($account->name); } elseif (empty($comment->name->value)) { @@ -1565,7 +1565,7 @@ function comment_preview(Comment $comment) { $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) { @@ -1654,7 +1654,7 @@ function template_preprocess_comment(&$variables) { $variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']); $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created'])); - if ($comment->pid->value) { + if ($comment->pid->target_id) { // Fetch and store the parent comment information for use in templates. $comment_parent = $comment->pid->entity; $account_parent = comment_prepare_author($comment); @@ -1709,14 +1709,14 @@ function template_preprocess_comment(&$variables) { if ($variables['new']) { $variables['attributes']['class'][] = 'new'; } - if (!$comment->uid->value) { + if (!$comment->uid->target_id) { $variables['attributes']['class'][] = 'by-anonymous'; } else { - if ($comment->uid->value == $variables['node']->uid) { + if ($comment->uid->target_id == $variables['node']->uid) { $variables['attributes']['class'][] = 'by-node-author'; } - if ($comment->uid->value == $variables['user']->uid) { + if ($comment->uid->target_id == $variables['user']->uid) { $variables['attributes']['class'][] = 'by-viewer'; } } diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index e333dd7..da359a4 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -59,7 +59,7 @@ function comment_reply(Node $node, $pid = NULL) { 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->nid->value != $node->nid) { + if ($comment->nid->target_id != $node->nid) { // Attempting to reply to a comment not belonging to the current nid. drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); drupal_goto("node/$node->nid"); @@ -121,7 +121,7 @@ function comment_approve($cid) { comment_save($comment); drupal_set_message(t('Comment approved.')); - drupal_goto('node/' . $comment->nid->value); + drupal_goto('node/' . $comment->nid->target_id); } throw new NotFoundHttpException(); } diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index ec56287..715b63d 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -131,13 +131,13 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'name': - $name = ($comment->uid->value == 0) ? config('user.settings')->get('anonymous') : $comment->name->value; + $name = ($comment->uid->target_id == 0) ? config('user.settings')->get('anonymous') : $comment->name->value; $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; case 'mail': - if ($comment->uid->value != 0) { - $account = user_load($comment->uid->value); + if ($comment->uid->target_id != 0) { + $account = user_load($comment->uid->target_id); $mail = $account->mail; } else { @@ -175,8 +175,8 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = 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; } break; diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index fca09ba..c13711f 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -37,8 +37,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 nodes. - if (!$comment->id() && !$comment->pid->value) { - $form['#action'] = url('comment/reply/' . $comment->nid->value); + if (!$comment->id() && !$comment->pid->target_id) { + $form['#action'] = url('comment/reply/' . $comment->nid->target_id); } if (isset($form_state['comment_preview'])) { @@ -163,7 +163,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 @@ -175,7 +175,8 @@ public function form(array $form, array &$form_state, EntityInterface $comment) // Add internal comment properties. foreach (array('cid', 'pid', 'nid', 'uid', 'node_type', '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); @@ -275,7 +276,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. diff --git a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php index a5ace07..dab8dc4 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php @@ -31,7 +31,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang // Pre-load associated users into cache to leverage multiple loading. $uids = array(); foreach ($entities as $entity) { - $uids[] = $entity->uid->value; + $uids[] = $entity->uid->target_id; } user_load_multiple(array_unique($uids)); @@ -40,13 +40,13 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang // Load all nodes of all comments at once. $nids = array(); foreach ($entities as $entity) { - $nids[$entity->nid->value] = $entity->nid->value; + $nids[$entity->nid->target_id] = $entity->nid->target_id; } $nodes = node_load_multiple($nids); foreach ($entities as $entity) { - if (isset($nodes[$entity->nid->value])) { - $node = $nodes[$entity->nid->value]; + if (isset($nodes[$entity->nid->target_id])) { + $node = $nodes[$entity->nid->target_id]; } else { throw new \InvalidArgumentException(t('Invalid node for comment.')); diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 4c91741..78a4ca4 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -104,10 +104,10 @@ protected function preSave(EntityInterface $comment) { // 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->value))->fetchField(); + $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid->target_id))->fetchField(); // Strip the "/" from the end of the thread. $max = rtrim($max, '/'); // We need to get the value at the correct depth. @@ -127,7 +127,7 @@ protected function preSave(EntityInterface $comment) { // 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->value, + ':nid' => $comment->nid->target_id, ))->fetchField(); if ($max == '') { @@ -150,7 +150,7 @@ protected function preSave(EntityInterface $comment) { // has the lock, just move to the next integer. do { $thread = $prefix . comment_int_to_alphadecimal(++$n) . '/'; - } while (!lock()->acquire("comment:{$comment->nid->value}:$thread")); + } while (!lock()->acquire("comment:{$comment->nid->target_id}:$thread")); $this->threadLock = $thread; } if (empty($comment->created->value)) { @@ -161,7 +161,7 @@ protected function preSave(EntityInterface $comment) { } // We test the value with '===' because we need to modify anonymous // users as well. - if ($comment->uid->value === $user->uid && isset($user->name)) { + if ($comment->uid->target_id === $user->uid && isset($user->name)) { $comment->name->value = $user->name; } // Add the values which aren't passed into the function. @@ -176,7 +176,7 @@ protected function preSave(EntityInterface $comment) { protected function postSave(EntityInterface $comment, $update) { $this->releaseThreadLock(); // Update the {node_comment_statistics} table prior to executing the hook. - $this->updateNodeStatistics($comment->nid->value); + $this->updateNodeStatistics($comment->nid->target_id); if ($comment->status->value == COMMENT_PUBLISHED) { module_invoke_all('comment_publish', $comment); } @@ -194,7 +194,7 @@ protected function postDelete($comments) { comment_delete_multiple($child_cids); foreach ($comments as $comment) { - $this->updateNodeStatistics($comment->nid->value); + $this->updateNodeStatistics($comment->nid->target_id); } } @@ -287,14 +287,14 @@ public function baseFieldDefinitions() { $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.'), - 'type' => 'entityreference_field', - 'settings' => array('entity type' => 'node'), + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'node'), 'required' => TRUE, ); $properties['langcode'] = array( @@ -310,8 +310,8 @@ public function baseFieldDefinitions() { $properties['uid'] = array( 'label' => t('User ID'), 'description' => t('The user ID of the comment author.'), - 'type' => 'entityreference_field', - 'settings' => array('entity type' => 'user'), + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'user'), ); $properties['name'] = array( 'label' => t('Name'), diff --git a/core/modules/comment/lib/Drupal/comment/FieldNewValue.php b/core/modules/comment/lib/Drupal/comment/FieldNewValue.php index c3e0d94..52875ca 100644 --- a/core/modules/comment/lib/Drupal/comment/FieldNewValue.php +++ b/core/modules/comment/lib/Drupal/comment/FieldNewValue.php @@ -28,7 +28,7 @@ public function getValue($langcode = NULL) { } $field = $this->parent->getParent(); $entity = $field->getParent(); - $this->value = node_mark($entity->nid->value, $entity->changed->value); + $this->value = node_mark($entity->nid->target_id, $entity->changed->value); } return $this->value; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php index c6175af..23f22d0 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php @@ -186,7 +186,7 @@ class Comment extends EntityNG implements ContentEntityInterface { protected $values = array( 'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))), 'name' => array(LANGUAGE_DEFAULT => array(0 => array('value' => ''))), - 'uid' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'uid' => array(LANGUAGE_DEFAULT => array(0 => array('target_id' => 0))), ); /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index 36f9f43..24a7931 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -67,7 +67,7 @@ function testCommentInterface() { // Test changing the comment author to "Anonymous". $this->drupalGet('comment/' . $comment->id() . '/edit'); $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => '')); - $this->assertTrue(empty($comment->name->value) && $comment->uid->value == 0, 'Comment author successfully changed to anonymous.'); + $this->assertTrue(empty($comment->name->value) && $comment->uid->target_id == 0, 'Comment author successfully changed to anonymous.'); // Test changing the comment author to an unverified user. $random_name = $this->randomName(); @@ -79,7 +79,7 @@ function testCommentInterface() { // Test changing the comment author to a verified user. $this->drupalGet('comment/' . $comment->id() . '/edit'); $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->name)); - $this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->value == $this->web_user->uid, 'Comment author successfully changed to a registered user.'); + $this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->target_id == $this->web_user->uid, 'Comment author successfully changed to a registered user.'); $this->drupalLogout(); @@ -92,7 +92,7 @@ function testCommentInterface() { $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.'); // Second reply to comment #3 creating comment #4. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 5421c0b..6bcc992 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -61,11 +61,11 @@ function testCommentTokenReplacement() { $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->nid->value; + $tests['[comment:node:nid]'] = $comment->nid->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 --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php index fa0145d..3006f94 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php @@ -78,8 +78,8 @@ public function setUp() { // 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->uid->value = 0; - $comment->nid->value = $this->node->nid; + $comment->uid->target_id = 0; + $comment->nid->target_id = $this->node->nid; $comment->subject->value = 'Test comment ' . $i; $comment->comment_body->value = 'Test body ' . $i; $comment->comment_body->format = 'full_html'; @@ -107,7 +107,7 @@ public function testBlockDisplay() { ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->nid->value; + $expected_result[$key]['nid'] = $comment->nid->target_id; $expected_result[$key]['subject'] = $comment->subject->value; $expected_result[$key]['cid'] = $comment->id(); $expected_result[$key]['changed'] = $comment->changed->value; @@ -139,7 +139,7 @@ public function testPageDisplay() { ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->nid->value; + $expected_result[$key]['nid'] = $comment->nid->target_id; $expected_result[$key]['subject'] = $comment->subject->value; $expected_result[$key]['changed'] = $comment->changed->value; $expected_result[$key]['created'] = $comment->created->value;