Commit f3732c68 authored by alexpott's avatar alexpott

Issue #2028025 by David Hernández, Berdir, larowlan, ceng, YesCT, a_thakur:...

Issue #2028025 by David Hernández, Berdir, larowlan, ceng, YesCT, a_thakur: Expand CommentInterface to provide methods.
parent 0b2c622b
......@@ -24,7 +24,7 @@
*/
function hook_comment_presave(Drupal\comment\Comment $comment) {
// Remove leading & trailing spaces from the comment subject.
$comment->subject->value = trim($comment->subject->value);
$comment->setSubject(trim($comment->getSubject()));
}
/**
......@@ -35,8 +35,8 @@ function hook_comment_presave(Drupal\comment\Comment $comment) {
*/
function hook_comment_insert(Drupal\comment\Comment $comment) {
// Reindex the node when comments are added.
if ($comment->entity_type->value == 'node') {
node_reindex_node_search($comment->entity_id->value);
if ($comment->getCommentedEntityTypeId() == 'node') {
node_reindex_node_search($comment->getCommentedEntityId());
}
}
......@@ -48,8 +48,8 @@ function hook_comment_insert(Drupal\comment\Comment $comment) {
*/
function hook_comment_update(Drupal\comment\Comment $comment) {
// Reindex the node when comments are updated.
if ($comment->entity_type->value == 'node') {
node_reindex_node_search($comment->entity_id->value);
if ($comment->getCommentedEntityTypeId() == 'node') {
node_reindex_node_search($comment->getCommentedEntityId());
}
}
......@@ -149,7 +149,7 @@ function hook_comment_view_alter(&$build, \Drupal\comment\Entity\Comment $commen
* The comment the action is being performed on.
*/
function hook_comment_publish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject->value)));
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->getSubject())));
}
/**
......@@ -159,7 +159,7 @@ function hook_comment_publish(Drupal\comment\Comment $comment) {
* The comment the action is being performed on.
*/
function hook_comment_unpublish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject->value)));
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->getSubject())));
}
/**
......@@ -194,7 +194,7 @@ function hook_comment_predelete(Drupal\comment\Comment $comment) {
* @see entity_delete_multiple()
*/
function hook_comment_delete(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject->value)));
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->getSubject())));
}
/**
......
This diff is collapsed.
......@@ -137,32 +137,27 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements[$original] = $comment->id();
break;
// Poster identity information for comments
// Poster identity information for comments.
case 'hostname':
$replacements[$original] = $sanitize ? check_plain($comment->hostname->value) : $comment->hostname->value;
$replacements[$original] = $sanitize ? check_plain($comment->getHostname()) : $comment->getHostname();
break;
case 'name':
$name = ($comment->getOwnerId() == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->name->value;
$name = ($comment->getOwnerId() == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->getAuthorName();
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
break;
case 'mail':
if ($comment->getOwnerId()) {
$mail = $comment->getOwner()->getEmail();
}
else {
$mail = $comment->mail->value;
}
$mail = $comment->getAuthorEmail();
$replacements[$original] = $sanitize ? check_plain($mail) : $mail;
break;
case 'homepage':
$replacements[$original] = $sanitize ? check_url($comment->homepage->value) : $comment->homepage->value;
$replacements[$original] = $sanitize ? check_url($comment->getHomepage()) : $comment->getHomepage();
break;
case 'title':
$replacements[$original] = $sanitize ? filter_xss($comment->subject->value) : $comment->subject->value;
$replacements[$original] = $sanitize ? filter_xss($comment->getSubject()) : $comment->getSubject();
break;
case 'body':
......@@ -180,28 +175,31 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements[$original] = url('comment/' . $comment->id() . '/edit', $url_options);
break;
// Default values for the chained tokens handled below.
// @todo Remove 'name' token in favour of 'author'. See
// https://drupal.org/node/920056.
case 'name':
case 'author':
$replacements[$original] = $sanitize ? filter_xss($comment->name->value) : $comment->name->value;
$name = $comment->getAuthorName();
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
break;
case 'parent':
if (!empty($comment->pid->target_id)) {
$parent = entity_load('comment', $comment->pid->target_id);
$replacements[$original] = $sanitize ? filter_xss($parent->subject->value) : $parent->subject->value;
if ($comment->hasParentComment()) {
$parent = $comment->getParentComment();
$replacements[$original] = $sanitize ? filter_xss($parent->getSubject()) : $parent->getSubject();
}
break;
case 'created':
$replacements[$original] = format_date($comment->created->value, 'medium', '', NULL, $langcode);
$replacements[$original] = format_date($comment->getCreatedTime(), 'medium', '', NULL, $langcode);
break;
case 'changed':
$replacements[$original] = format_date($comment->changed->value, 'medium', '', NULL, $langcode);
$replacements[$original] = format_date($comment->getChangedTime(), 'medium', '', NULL, $langcode);
break;
case 'entity':
$entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
$entity = $comment->getCommentedEntity();
$title = $entity->label();
$replacements[$original] = $sanitize ? filter_xss($title) : $title;
break;
......@@ -210,8 +208,8 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
// Support legacy comment node tokens, since tokes are embedded in
// user data and can't be upgraded directly.
// @todo Remove in Drupal 9, see https://drupal.org/node/2031901.
if ($comment->entity_type->value == 'node') {
$entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
if ($comment->getCommentedEntityTypeId() == 'node') {
$entity = $comment->getCommentedEntity();
$title = $entity->label();
$replacements[$original] = $sanitize ? filter_xss($title) : $title;
}
......@@ -224,24 +222,24 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
// Chained token relationships.
if ($entity_tokens = $token_service->findwithPrefix($tokens, 'entity')) {
$entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
$replacements += $token_service->generate($comment->entity_type->value, $entity_tokens, array($comment->entity_type->value => $entity), $options);
$entity = $comment->getCommentedEntity();
$replacements += $token_service->generate($comment->getCommentedEntityTypeId(), $entity_tokens, array($comment->getCommentedEntityTypeId() => $entity), $options);
}
if (($node_tokens = $token_service->findwithPrefix($tokens, 'node')) && $comment->entity_type->value == 'node') {
$node = entity_load($comment->entity_type->value, $comment->entity_id->value);
if (($node_tokens = $token_service->findwithPrefix($tokens, 'node')) && $comment->getCommentedEntityTypeId() == 'node') {
$node = $comment->getCommentedEntity();
$replacements += $token_service->generate('node', $node_tokens, array('node' => $node), $options);
}
if ($date_tokens = $token_service->findwithPrefix($tokens, 'created')) {
$replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->created->value), $options);
$replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->getCreatedTime()), $options);
}
if ($date_tokens = $token_service->findwithPrefix($tokens, 'changed')) {
$replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->changed->value), $options);
$replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->getChangedTime()), $options);
}
if (($parent_tokens = $token_service->findwithPrefix($tokens, 'parent')) && $parent = $comment->pid->entity) {
if (($parent_tokens = $token_service->findwithPrefix($tokens, 'parent')) && $parent = $comment->getParentComment()) {
$replacements += $token_service->generate('comment', $parent_tokens, array('comment' => $parent), $options);
}
......@@ -255,7 +253,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$entity = !empty($data['entity']) ? $data['entity'] : $data['node'];
foreach ($tokens as $name => $original) {
switch($name) {
switch ($name) {
case 'comment-count':
$count = 0;
$fields = array_keys(\Drupal::service('comment.manager')->getFields($entity->getEntityTypeId()));
......
......@@ -29,7 +29,7 @@ public function getValue() {
// Field id is of the form {entity_type}__{field_name}. We set the
// optional limit param to explode() in case the user adds a field with __
// in the name.
$parts = explode('__', $entity->field_id->value, 2);
$parts = explode('__', $entity->getFieldId(), 2);
if ($parts && count($parts) == 2) {
$this->value = end($parts);
}
......@@ -46,7 +46,7 @@ public function setValue($value, $notify = TRUE) {
// Also set the field id.
$field = $this->parent->getParent();
$entity = $field->getParent();
$entity->field_id = $entity->entity_type->value . '__' . $value;
$entity->field_id = $entity->getCommentedEntityTypeId() . '__' . $value;
}
}
......
......@@ -86,8 +86,8 @@ protected function init(array &$form_state) {
public function form(array $form, array &$form_state) {
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $this->entity;
$entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value);
$field_name = $comment->field_name->value;
$entity = $this->entityManager->getStorageController($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());
$field_name = $comment->getFieldName();
$instance = $this->fieldInfo->getInstance($entity->getEntityTypeId(), $entity->bundle(), $field_name);
// Use #comment-form as unique jump target, regardless of entity type.
......@@ -104,7 +104,7 @@ public function form(array $form, array &$form_state) {
// If not replying to a comment, use our dedicated page callback for new
// Comments on entities.
if (!$comment->id() && empty($comment->pid->target_id)) {
if (!$comment->id() && !$comment->hasParentComment()) {
$form['#action'] = url('comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name);
}
......@@ -124,11 +124,11 @@ public function form(array $form, array &$form_state) {
// Prepare default values for form elements.
if ($is_admin) {
$author = $comment->name->value;
$status = (isset($comment->status->value) ? $comment->status->value : CommentInterface::NOT_PUBLISHED);
$author = $comment->getAuthorName();
$status = $comment->isPublished();
if (empty($form_state['comment_preview'])) {
$form['#title'] = $this->t('Edit comment %title', array(
'%title' => $comment->subject->value,
'%title' => $comment->getSubject(),
));
}
}
......@@ -137,14 +137,14 @@ public function form(array $form, array &$form_state) {
$author = $this->currentUser->getUsername();
}
else {
$author = ($comment->name->value ? $comment->name->value : '');
$author = ($comment->getAuthorName() ? $comment->getAuthorName() : '');
}
$status = ($this->currentUser->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED);
}
$date = '';
if ($comment->id()) {
$date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value);
$date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->getCreatedTime());
}
// Add the author name field depending on the current user.
......@@ -172,7 +172,7 @@ public function form(array $form, array &$form_state) {
$form['author']['mail'] = array(
'#type' => 'email',
'#title' => $this->t('E-mail'),
'#default_value' => $comment->mail->value,
'#default_value' => $comment->getAuthorEmail(),
'#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#maxlength' => 64,
'#size' => 30,
......@@ -183,7 +183,7 @@ public function form(array $form, array &$form_state) {
$form['author']['homepage'] = array(
'#type' => 'url',
'#title' => $this->t('Homepage'),
'#default_value' => $comment->homepage->value,
'#default_value' => $comment->getHomepage(),
'#maxlength' => 255,
'#size' => 30,
'#access' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
......@@ -213,7 +213,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'textfield',
'#title' => $this->t('Subject'),
'#maxlength' => 64,
'#default_value' => $comment->subject->value,
'#default_value' => $comment->getSubject(),
'#access' => $instance->getSetting('subject'),
);
......@@ -238,9 +238,10 @@ public function form(array $form, array &$form_state) {
*/
protected function actions(array $form, array &$form_state) {
$element = parent::actions($form, $form_state);
/* @var \Drupal\comment\CommentInterface $comment */
$comment = $this->entity;
$entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value);
$instance = $this->fieldInfo->getInstance($comment->entity_type->value, $entity->bundle(), $comment->field_name->value);
$entity = $comment->getCommentedEntity();
$instance = $this->fieldInfo->getInstance($comment->getCommentedEntityTypeId(), $entity->bundle(), $comment->getFieldName());
$preview_mode = $instance->getSetting('preview');
// No delete action on the comment form.
......@@ -308,10 +309,10 @@ public function validate(array $form, array &$form_state) {
public function buildEntity(array $form, array &$form_state) {
$comment = parent::buildEntity($form, $form_state);
if (!empty($form_state['values']['date']) && $form_state['values']['date'] instanceOf DrupalDateTime) {
$comment->created->value = $form_state['values']['date']->getTimestamp();
$comment->setCreatedTime($form_state['values']['date']->getTimestamp());
}
else {
$comment->created->value = REQUEST_TIME;
$comment->setCreatedTime(REQUEST_TIME);
}
$comment->changed->value = REQUEST_TIME;
return $comment;
......@@ -327,28 +328,29 @@ public function submit(array $form, array &$form_state) {
// If the comment was posted by a registered user, assign the author's ID.
// @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))) {
$author_name = $comment->getAuthorName();
if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
$comment->setOwner($account);
}
// If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default.
if ($comment->is_anonymous && (!isset($comment->name->value) || $comment->name->value === '')) {
$comment->name->value = $this->config('user.settings')->get('anonymous');
if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {
$comment->setAuthorName($this->config('user.settings')->get('anonymous'));
}
// Validate the comment's subject. If not specified, extract from comment
// body.
if (trim($comment->subject->value) == '') {
if (trim($comment->getSubject()) == '') {
// The body may be in any format, so:
// 1) Filter it into HTML
// 2) Strip out all HTML tags
// 3) Convert entities back to plain-text.
$comment_text = $comment->comment_body->processed;
$comment->subject = Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE);
$comment->setSubject(Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE));
// Edge cases where the comment body is populated only by HTML tags will
// require a default subject.
if ($comment->subject->value == '') {
$comment->subject->value = $this->t('(No subject)');
if ($comment->getSubject() == '') {
$comment->setSubject($this->t('(No subject)'));
}
}
......@@ -376,7 +378,7 @@ public function preview(array &$form, array &$form_state) {
public function save(array $form, array &$form_state) {
$entity = entity_load($form_state['values']['entity_type'], $form_state['values']['entity_id']);
$comment = $this->entity;
$field_name = $comment->field_name->value;
$field_name = $comment->getFieldName();
$uri = $entity->urlInfo();
if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == COMMENT_OPEN)) {
......@@ -389,10 +391,10 @@ public function save(array $form, array &$form_state) {
$form_state['values']['cid'] = $comment->id();
// Add an entry to the watchdog log.
watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject->value), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id())));
watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id())));
// Explain the approval queue if necessary.
if ($comment->status->value == CommentInterface::NOT_PUBLISHED) {
if (!$comment->isPublished()) {
if (!$this->currentUser->hasPermission('administer comments')) {
drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
}
......@@ -411,8 +413,8 @@ public function save(array $form, array &$form_state) {
$uri['options'] += array('query' => $query, 'fragment' => 'comment-' . $comment->id());
}
else {
watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject->value), WATCHDOG_WARNING);
drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject->value)), 'error');
watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_WARNING);
drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject())), 'error');
// Redirect the user to the entity they are commenting on.
}
$form_state['redirect_route'] = $uri;
......
......@@ -26,6 +26,231 @@
*/
const PUBLISHED = 1;
/**
* Determines if this comment is a reply to another comment.
*
* @return bool
* TRUE if the comment has a parent comment otherwise FALSE.
*/
public function hasParentComment();
/**
* Returns the parent comment entity if this is a reply to a comment.
*
* @return \Drupal\comment\CommentInterface|NULL
* A comment entity of the parent comment or NULL if there is no parent.
*/
public function getParentComment();
/**
* Returns the entity to which the comment is attached.
*
* @return \Drupal\Core\Entity\EntityInterface
* The entity on which the comment is attached.
*/
public function getCommentedEntity();
/**
* Returns the ID of the entity to which the comment is attached.
*
* @return int
* The ID of the entity to which the comment is attached.
*/
public function getCommentedEntityId();
/**
* Returns the type of the entity to which the comment is attached.
*
* @return string
* An entity type.
*/
public function getCommentedEntityTypeId();
/**
* Returns the field ID of the comment field the comment is attached to.
*
* @return string
* The field identifier of the field the comment is attached to.
*/
public function getFieldId();
/**
* Sets the field ID for which this comment is attached.
*
* @param string $field_id
* The field identifier, usually formatted: {entity_type}__{field_name},
* for example, node__comment.
*
* @return $this
* The class instance that this method is called on.
*/
public function setFieldId($field_id);
/**
* Returns the name of the field the comment is attached to.
*
* @return string
* The name of the field the comment is attached to.
*/
public function getFieldName();
/**
* Returns the subject of the comment.
*
* @return string
* The subject of the comment.
*/
public function getSubject();
/**
* Sets the subject of the comment.
*
* @param string $subject
* The subject of the comment.
*
* @return $this
* The class instance that this method is called on.
*/
public function setSubject($subject);
/**
* Returns the comment author's name.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @return string
* The name of the comment author.
*/
public function getAuthorName();
/**
* Sets the name of the author of the comment.
*
* @param string $name
* A string containing the name of the author.
*
* @return $this
* The class instance that this method is called on.
*/
public function setAuthorName($name);
/**
* Returns the comment author's e-mail address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @return string
* The e-mail address of the author of the comment.
*/
public function getAuthorEmail();
/**
* Returns the comment author's home page address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @return string
* The homepage address of the author of the comment.
*/
public function getHomepage();
/**
* Sets the comment author's home page address.
*
* For anonymous authors, this is the value as typed in the comment form.
*
* @param string $homepage
* The homepage address of the author of the comment.
*
* @return $this
* The class instance that this method is called on.
*/
public function setHomepage($homepage);
/**
* Returns the comment author's hostname.
*
* @return string
* The hostname of the author of the comment.
*/
public function getHostname();
/**
* Sets the hostname of the author of the comment.
*
* @param string $hostname
* The hostname of the author of the comment.
*
* @return $this
* The class instance that this method is called on.
*/
public function setHostname($hostname);
/**
* Returns the time that the comment was created.
*
* @return int
* The timestamp of when the comment was created.
*/
public function getCreatedTime();
/**
* Sets the creation date of the comment.
*
* @param int $created
* The timestamp of when the comment was created.
*
* @return $this
* The class instance that this method is called on.
*/
public function setCreatedTime($created);
/**
* Returns the timestamp of when the comment was updated.
*
* @return int
* The timestamp of when the comment was updated.
*/
public function getChangedTime();
/**
* Checks if the comment is published.
*
* @return bool
* TRUE if the comment is published.
*/
public function isPublished();
/**
* Sets the published status of the comment entity.
*
* @param bool $status
* Set to TRUE to publish the comment, FALSE to unpublish.
*
* @return \Drupal\comment\CommentInterface
* The class instance that this method is called on.
*/
public function setPublished($status);
/**
* Returns the alphadecimal representation of the comment's place in a thread.
*
* @return string
* The alphadecimal representation of the comment's place in a thread.
*/
public function getThread();
/**
* Sets the alphadecimal representation of the comment's place in a thread.
*
* @param string $thread
* The alphadecimal representation of the comment's place in a thread.
*
* @return $this
* The class instance that this method is called on.
*/
public function setThread($thread);
/**
* Returns the permalink URL for this comment.
*
......
......@@ -100,8 +100,8 @@ public function __construct(FieldInfo $field_info, EntityManagerInterface $entit
*/
public function getParentEntityUri(CommentInterface $comment) {
return $this->entityManager
->getStorageController($comment->entity_type->value)
->load($comment->entity_id->value)
->getStorageController($comment->getCommentedEntityTypeId())
->load($comment->getCommentedEntityId())
->urlInfo();
}
......
......@@ -55,9 +55,9 @@ public function updateEntityStatistics(CommentInterface $comment) {
$query = $this->database->select('comment', 'c');
$query->addExpression('COUNT(cid)');
$count = $query->condition('c.entity_id', $comment->entity_id->value)
->condition('c.entity_type', $comment->entity_type->value)
->condition('c.field_id', $comment->field_id->value)
$count = $query->condition('c.entity_id', $comment->getCommentedEntityId())
->condition('c.entity_type', $comment->getCommentedEntityTypeId())
->condition('c.field_id', $comment->getFieldId())
->condition('c.status', CommentInterface::PUBLISHED)
->execute()
->fetchField();
......@@ -66,9 +66,9 @@ public function updateEntityStatistics(CommentInterface $comment) {
// Comments exist.
$last_reply = $this->database->select('comment', 'c')
->fields('c', array('cid', 'name', 'changed', 'uid'))
->condition('c.entity_id', $comment->entity_id->value)
->condition('c.entity_type', $comment->entity_type->value)
->condition('c.field_id', $comment->field_id->value)
->condition('c.entity_id', $comment->getCommentedEntityId())
->condition('c.entity_type', $comment->getCommentedEntityTypeId())
->condition('c.field_id', $comment->getFieldId())
->condition('c.status', CommentInterface::PUBLISHED)
->orderBy('c.created', 'DESC')
->range(0, 1)
......@@ -84,15 +84,15 @@ public function updateEntityStatistics(CommentInterface $comment) {
'last_comment_uid' => $last_reply->uid,
))
->key(array(
'entity_id' => $comment->entity_id->value,
'entity_type' => $comment->entity_type->value,
'field_id' => $comment->field_id->value,
'entity_id' => $comment->getCommentedEntityId(),
'entity_type' => $comment->getCommentedEntityTypeId(),
'field_id' => $comment->getFieldId(),
))
->execute();
}
else {
// Comments do not exist.
$entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
$en