From 4ec8332e1b2f63406a2b9488cea1ecbafd408cec Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Mon, 18 Feb 2013 11:20:20 +0400 Subject: [PATCH 3/3] Fix access to files and clean-up remains of ER transition --- core/modules/comment/comment.admin.inc | 4 ++-- core/modules/comment/comment.module | 15 +++++++-------- .../lib/Drupal/comment/CommentFormController.php | 4 ++-- .../lib/Drupal/comment/CommentStorageController.php | 10 +++++----- .../lib/Drupal/comment/Plugin/views/field/LinkReply.php | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 071c197..0e51f39 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -196,7 +196,7 @@ function comment_admin_overview($form, &$form_state, $arg) { foreach ($comments as $comment) { // Use the first entity label. - $entity = $entities[$comment->entity_type->value][$comment->entity_id->value]; + $entity = $entities[$comment->entity_type->value][$comment->entity_id->target_id]; $comment->entity_title = $entity->label(); $comment->entity_uri = $entity->uri(); $comment_body = field_get_items($comment, 'comment_body'); @@ -381,7 +381,7 @@ function comment_confirm_delete($form, &$form_state, Comment $comment) { $form_state['comment'] = $comment; // Always provide entity id in the same form key as in the entity edit form. $form['cid'] = array('#type' => 'value', '#value' => $comment->id()); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); $uri = $entity->uri(); return confirm_form( $form, diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index de5d3a7..b9d523a 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -596,7 +596,7 @@ function comment_permission() { * The comment listing set to the page on which the comment appears. */ function comment_permalink($cid) { - if (($comment = comment_load($cid)) && ($entity = entity_load($comment->entity_type->value, $comment->entity_id->value))) { + if (($comment = comment_load($cid)) && ($entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id))) { $instance = field_info_instance($entity->entityType(), $comment->field_name->value, $entity->bundle()); // Find the current display page for this comment. @@ -1543,7 +1543,7 @@ function comment_edit_page(Comment $comment) { function comment_preview(Comment $comment) { global $user; $preview_build = array(); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); if (!form_get_errors()) { // Attach the user and time information. @@ -2073,10 +2073,9 @@ function comment_rdf_mapping() { function comment_file_download_access($field, EntityInterface $entity, File $file) { if ($entity->entityType() == 'comment') { if (user_access('access comments') && $entity->status->value == COMMENT_PUBLISHED || user_access('administer comments')) { - $commented_entity = entity_load($entity->entity_type->value, $entity->entity_id->value); - if ($commented_entity instanceof AccessibleInterface) { - return $commented_entity->access('view'); - } + $commented_entity = entity_load($entity->entity_type->value, $entity->entity_id->target_id); + // Check access to parent entity. + return comment_reply_access($commented_entity); } return FALSE; } @@ -2141,14 +2140,14 @@ function comment_get_comment_fields($entity_type = NULL) { function comment_mark(Comment $comment) { global $user; $cache = &drupal_static(__FUNCTION__, array()); - $cid = $comment->entity_id->value . '__' . $comment->entity_type->value; + $cid = $comment->entity_id->target_id . '__' . $comment->entity_type->value; if (!$user->uid) { return MARK_READ; } if (!isset($cache[$cid])) { if ($comment->entity_type->value == 'node' && module_exists('history')) { - $cache[$cid] = history_read($comment->entity_id->value); + $cache[$cid] = history_read($comment->entity_id->target_id); } else { // @todo - decide how to handle last viewed for other entities. For now diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 35a27e5..bf9849f 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -22,7 +22,7 @@ class CommentFormController extends EntityFormControllerNG { public function form(array $form, array &$form_state, EntityInterface $comment) { global $user; - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); $instance = field_info_instance($comment->entity_type->value, $comment->field_name->value, $entity->bundle()); // Use #comment-form as unique jump target, regardless of entity type. @@ -173,7 +173,7 @@ public function form(array $form, array &$form_state, EntityInterface $comment) protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); $comment = $this->getEntity($form_state); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); $instance = field_info_instance($comment->entity_type->value, $comment->field_name->value, $entity->bundle()); $preview_mode = $instance['settings']['comment']['comment_preview']; diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index c536768..39d95ee 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -201,7 +201,7 @@ protected function updateEntityStatistics($comment) { $query = db_select('comment', 'c'); $query->addExpression('COUNT(cid)'); - $count = $query->condition('c.entity_id', $comment->entity_id->value) + $count = $query->condition('c.entity_id', $comment->entity_id->target_id) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_name', $comment->field_name->value) ->condition('c.status', COMMENT_PUBLISHED) @@ -212,7 +212,7 @@ protected function updateEntityStatistics($comment) { // Comments exist. $last_reply = db_select('comment', 'c') ->fields('c', array('cid', 'name', 'changed', 'uid')) - ->condition('c.entity_id', $comment->entity_id->value) + ->condition('c.entity_id', $comment->entity_id->target_id) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_name', $comment->field_name->value) ->condition('c.status', COMMENT_PUBLISHED) @@ -228,14 +228,14 @@ protected function updateEntityStatistics($comment) { 'last_comment_name' => $last_reply->uid ? '' : $last_reply->name, 'last_comment_uid' => $last_reply->uid, )) - ->condition('entity_id', $comment->entity_id->value) + ->condition('entity_id', $comment->entity_id->target_id) ->condition('entity_type', $comment->entity_type->value) ->condition('field_name', $comment->field_name->value) ->execute(); } else { // Comments do not exist. - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); db_update('comment_entity_statistics') ->fields(array( 'cid' => 0, @@ -248,7 +248,7 @@ protected function updateEntityStatistics($comment) { // Get uid from entity or default to logged in user if none exists. 'last_comment_uid' => isset($entity->uid) ? $entity->uid : $user->uid, )) - ->condition('entity_id', $comment->entity_id->value) + ->condition('entity_id', $comment->entity_id->target_id) ->condition('entity_type', $comment->entity_type->value) ->condition('field_name', $comment->field_name->value) ->execute(); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php index 6782fae..081fa05 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php @@ -31,7 +31,7 @@ function render_link($data, $values) { $comment = $this->get_entity($values); $this->options['alter']['make_link'] = TRUE; - $this->options['alter']['path'] = "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->value}/{$comment->field_name->value}/{$comment->id()}"; + $this->options['alter']['path'] = "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->target_id}/{$comment->field_name->value}/{$comment->id()}"; return $text; } -- 1.7.10.4