Commit 837d726f authored by alexpott's avatar alexpott

Issue #1498662 by andypost, larowlan | dawehner: Refactor comment entity...

Issue #1498662 by andypost, larowlan | dawehner: Refactor comment entity properties to multilingual.
parent ff3e56e8
......@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the Comment module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\field\Entity\FieldConfig;
/**
......@@ -48,7 +49,7 @@ function comment_schema() {
'type' => 'varchar',
'not null' => TRUE,
'default' => 'node',
'length' => 255,
'length' => EntityTypeInterface::ID_MAX_LENGTH,
'description' => 'The entity_type of the entity to which this comment is a reply.',
),
'field_name' => array(
......
......@@ -515,7 +515,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
* to consider the trailing "/" so we use a substring only.
*/
function comment_get_thread(EntityInterface $entity, $field_name, $mode, $comments_per_page, $pager_id = 0) {
$query = db_select('comment', 'c')
$query = db_select('comment_field_data', 'c')
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
if ($pager_id) {
$query->element($pager_id);
......@@ -525,6 +525,7 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen
->condition('c.entity_id', $entity->id())
->condition('c.entity_type', $entity->getEntityTypeId())
->condition('c.field_name', $field_name)
->condition('default_langcode', 1)
->addTag('entity_access')
->addTag('comment_filter')
->addMetaData('base_table', 'comment')
......@@ -532,12 +533,13 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen
->addMetaData('field_name', $field_name)
->limit($comments_per_page);
$count_query = db_select('comment', 'c');
$count_query = db_select('comment_field_data', 'c');
$count_query->addExpression('COUNT(*)');
$count_query
->condition('c.entity_id', $entity->id())
->condition('c.entity_type', $entity->getEntityTypeId())
->condition('c.field_name', $field_name)
->condition('default_langcode', 1)
->addTag('entity_access')
->addTag('comment_filter')
->addMetaData('base_table', 'comment')
......
......@@ -23,7 +23,15 @@ function comment_views_data() {
$data['comment']['table']['entity type'] = 'comment';
$data['comment']['table']['wizard_id'] = 'comment';
$data['comment']['subject'] = array(
$data['comment_field_data']['table']['group'] = t('Comment');
$data['comment_field_data']['table']['entity type'] = 'comment';
$data['comment_field_data']['table']['join']['comment'] = array(
'type' => 'INNER',
'left_field' => 'cid',
'field' => 'cid',
);
$data['comment_field_data']['subject'] = array(
'title' => t('Title'),
'help' => t('The title of the comment.'),
'field' => array(
......@@ -57,7 +65,7 @@ function comment_views_data() {
),
);
$data['comment']['name'] = array(
$data['comment_field_data']['name'] = array(
'title' => t('Author'),
'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
'field' => array(
......@@ -74,7 +82,7 @@ function comment_views_data() {
),
);
$data['comment']['homepage'] = array(
$data['comment_field_data']['homepage'] = array(
'title' => t("Author's website"),
'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
'field' => array(
......@@ -91,7 +99,7 @@ function comment_views_data() {
),
);
$data['comment']['hostname'] = array(
$data['comment_field_data']['hostname'] = array(
'title' => t('Hostname'),
'help' => t('Hostname of user that posted the comment.'),
'field' => array(
......@@ -108,7 +116,7 @@ function comment_views_data() {
),
);
$data['comment']['mail'] = array(
$data['comment_field_data']['mail'] = array(
'title' => t('Email'),
'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
'field' => array(
......@@ -125,7 +133,7 @@ function comment_views_data() {
),
);
$data['comment']['created'] = array(
$data['comment_field_data']['created'] = array(
'title' => t('Post date'),
'help' => t('Date and time of when the comment was created.'),
'field' => array(
......@@ -158,7 +166,7 @@ function comment_views_data() {
);
}
$data['comment']['changed'] = array(
$data['comment_field_data']['changed'] = array(
'title' => t('Updated date'),
'help' => t('Date and time of when the comment was last updated.'),
'field' => array(
......@@ -172,7 +180,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_fulldata'] = array(
$data['comment_field_data']['changed_fulldata'] = array(
'title' => t('Created date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
......@@ -181,7 +189,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_year_month'] = array(
$data['comment_field_data']['changed_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
......@@ -190,7 +198,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_year'] = array(
$data['comment_field_data']['changed_year'] = array(
'title' => t('Created year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
......@@ -199,7 +207,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_month'] = array(
$data['comment_field_data']['changed_month'] = array(
'title' => t('Created month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
......@@ -208,7 +216,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_day'] = array(
$data['comment_field_data']['changed_day'] = array(
'title' => t('Created day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
......@@ -217,7 +225,7 @@ function comment_views_data() {
),
);
$data['comment']['changed_week'] = array(
$data['comment_field_data']['changed_week'] = array(
'title' => t('Created week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
......@@ -226,7 +234,7 @@ function comment_views_data() {
),
);
$data['comment']['status'] = array(
$data['comment_field_data']['status'] = array(
'title' => t('Approved status'),
'help' => t('Whether the comment is approved (or still in the moderation queue).'),
'field' => array(
......@@ -285,7 +293,7 @@ function comment_views_data() {
),
);
$data['comment']['thread'] = array(
$data['comment_field_data']['thread'] = array(
'field' => array(
'title' => t('Depth'),
'help' => t('Display the depth of the comment if it is threaded.'),
......@@ -298,7 +306,7 @@ function comment_views_data() {
),
);
$data['comment']['entity_id'] = array(
$data['comment_field_data']['entity_id'] = array(
'title' => t('Entity ID'),
'help' => t('The Entity ID to which the comment is a reply to.'),
'field' => array(
......@@ -315,7 +323,7 @@ function comment_views_data() {
),
);
$data['comment']['entity_type'] = array(
$data['comment_field_data']['entity_type'] = array(
'title' => t('Entity type'),
'help' => t('The Entity type to which the comment is a reply to.'),
'field' => array(
......@@ -332,7 +340,7 @@ function comment_views_data() {
),
);
$data['comment']['field_name'] = array(
$data['comment_field_data']['field_name'] = array(
'title' => t('Comment field name'),
'help' => t('The Field name from which the comment originated.'),
'field' => array(
......@@ -374,7 +382,7 @@ function comment_views_data() {
continue;
}
if ($fields = \Drupal::service('comment.manager')->getFields($type)) {
$data['comment'][$type] = array(
$data['comment_field_data'][$type] = array(
'relationship' => array(
'title' => $entity_type->getLabel(),
'help' => t('The @entity_type to which the comment is a reply to.', array('@entity_type' => $entity_type->getLabel())),
......@@ -387,7 +395,7 @@ function comment_views_data() {
array(
'field' => 'entity_type',
'value' => $type,
'table' => 'comment'
'table' => 'comment_field_data'
),
),
),
......@@ -395,7 +403,7 @@ function comment_views_data() {
}
}
$data['comment']['uid'] = array(
$data['comment_field_data']['uid'] = array(
'title' => t('Author uid'),
'help' => t('If you need more fields than the uid add the comment: author relationship'),
'relationship' => array(
......@@ -417,7 +425,7 @@ function comment_views_data() {
),
);
$data['comment']['pid'] = array(
$data['comment_field_data']['pid'] = array(
'title' => t('Parent CID'),
'help' => t('The Comment ID of the parent comment.'),
'field' => array(
......@@ -637,12 +645,9 @@ function comment_views_data_alter(&$data) {
),
);
if ($entity_type_id == 'node') {
// Node properties lives in data_table.
$table = $entity_type->getDataTable();
}
else {
$table = $base_table;
// Multilingual properties are stored in data table.
if (!($table = $entity_type->getDataTable())) {
$table = $entity_type->getBaseTable();
}
$data[$table]['uid_touch'] = array(
'title' => t('User posted or commented'),
......@@ -673,7 +678,7 @@ function comment_views_data_alter(&$data) {
'relationship' => array(
'group' => t('Comment'),
'label' => t('Comments'),
'base' => 'comment',
'base' => 'comment_field_data',
'base field' => 'entity_id',
'relationship field' => $entity_type->getKey('id'),
'id' => 'standard',
......
......@@ -54,13 +54,13 @@ display:
node:
field: node
id: node
table: comment
table: comment_field_data
required: true
plugin_id: standard
fields:
subject:
id: subject
table: comment
table: comment_field_data
field: subject
relationship: none
plugin_id: comment
......@@ -111,7 +111,7 @@ display:
link_to_entity: false
changed:
id: changed
table: comment
table: comment_field_data
field: changed
relationship: none
plugin_id: date
......@@ -164,7 +164,7 @@ display:
filters:
status:
value: true
table: comment
table: comment_field_data
field: status
id: status
plugin_id: boolean
......@@ -184,7 +184,7 @@ display:
sorts:
created:
id: created
table: comment
table: comment_field_data
field: created
relationship: none
group_type: group
......
......@@ -184,23 +184,25 @@ public function update(CommentInterface $comment) {
return;
}
$query = $this->database->select('comment', 'c');
$query = $this->database->select('comment_field_data', 'c');
$query->addExpression('COUNT(cid)');
$count = $query->condition('c.entity_id', $comment->getCommentedEntityId())
->condition('c.entity_type', $comment->getCommentedEntityTypeId())
->condition('c.field_name', $comment->getFieldName())
->condition('c.status', CommentInterface::PUBLISHED)
->condition('default_langcode', 1)
->execute()
->fetchField();
if ($count > 0) {
// Comments exist.
$last_reply = $this->database->select('comment', 'c')
$last_reply = $this->database->select('comment_field_data', 'c')
->fields('c', array('cid', 'name', 'changed', 'uid'))
->condition('c.entity_id', $comment->getCommentedEntityId())
->condition('c.entity_type', $comment->getCommentedEntityTypeId())
->condition('c.field_name', $comment->getFieldName())
->condition('c.status', CommentInterface::PUBLISHED)
->condition('default_langcode', 1)
->orderBy('c.created', 'DESC')
->range(0, 1)
->execute()
......
......@@ -81,10 +81,11 @@ public function updateEntityStatistics(CommentInterface $comment) {
* {@inheritdoc}
*/
public function getMaxThread(CommentInterface $comment) {
$query = $this->database->select('comment', 'c')
$query = $this->database->select('comment_field_data', 'c')
->condition('entity_id', $comment->getCommentedEntityId())
->condition('field_name', $comment->getFieldName())
->condition('entity_type', $comment->getCommentedEntityTypeId());
->condition('entity_type', $comment->getCommentedEntityTypeId())
->condition('default_langcode', 1);
$query->addExpression('MAX(thread)', 'thread');
return $query->execute()
->fetchField();
......@@ -94,11 +95,12 @@ public function getMaxThread(CommentInterface $comment) {
* {@inheritdoc}
*/
public function getMaxThreadPerThread(CommentInterface $comment) {
$query = $this->database->select('comment', 'c')
$query = $this->database->select('comment_field_data', 'c')
->condition('entity_id', $comment->getCommentedEntityId())
->condition('field_name', $comment->getFieldName())
->condition('entity_type', $comment->getCommentedEntityTypeId())
->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE');
->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE')
->condition('default_langcode', 1);
$query->addExpression('MAX(thread)', 'thread');
return $query->execute()
->fetchField();
......@@ -110,8 +112,8 @@ public function getMaxThreadPerThread(CommentInterface $comment) {
public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $divisor = 1) {
// Count how many comments (c1) are before $comment (c2) in display order.
// This is the 0-based display ordinal.
$query = $this->database->select('comment', 'c1');
$query->innerJoin('comment', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
$query = $this->database->select('comment_field_data', 'c1');
$query->innerJoin('comment_field_data', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
$query->addExpression('COUNT(*)', 'count');
$query->condition('c2.cid', $comment->id());
if (!$this->currentUser->hasPermission('administer comments')) {
......@@ -131,6 +133,9 @@ public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $div
$query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) - 1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) - 1))');
}
$query->condition('c1.default_langcode', 1);
$query->condition('c2.default_langcode', 1);
$ordinal = $query->execute()->fetchField();
return ($divisor > 1) ? floor($ordinal / $divisor) : $ordinal;
......@@ -155,12 +160,13 @@ public function getNewCommentPageNumber($total_comments, $new_comments, ContentE
// Threaded comments.
// 1. Find all the threads with a new comment.
$unread_threads_query = $this->database->select('comment')
$unread_threads_query = $this->database->select('comment_field_data', 'comment')
->fields('comment', array('thread'))
->condition('entity_id', $entity->id())
->condition('entity_type', $entity->getEntityTypeId())
->condition('field_name', $field_name)
->condition('status', CommentInterface::PUBLISHED)
->condition('default_langcode', 1)
->orderBy('created', 'DESC')
->orderBy('cid', 'DESC')
->range(0, $new_comments);
......@@ -179,10 +185,12 @@ public function getNewCommentPageNumber($total_comments, $new_comments, ContentE
$first_thread = substr($first_thread, 0, -1);
// Find the number of the first comment of the first unread thread.
$count = $this->database->query('SELECT COUNT(*) FROM {comment} WHERE entity_id = :entity_id
$count = $this->database->query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id
AND entity_type = :entity_type
AND field_name = :field_name
AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
AND status = :status
AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread
AND default_langcode = 1', array(
':status' => CommentInterface::PUBLISHED,
':entity_id' => $entity->id(),
':field_name' => $field_name,
......@@ -198,9 +206,10 @@ public function getNewCommentPageNumber($total_comments, $new_comments, ContentE
* {@inheritdoc}
*/
public function getChildCids(array $comments) {
return $this->database->select('comment', 'c')
return $this->database->select('comment_field_data', 'c')
->fields('c', array('cid'))
->condition('pid', array_keys($comments))
->condition('default_langcode', 1)
->execute()
->fetchCol();
}
......@@ -213,19 +222,16 @@ public function getSchema() {
// Marking the respective fields as NOT NULL makes the indexes more
// performant.
$schema['comment']['fields']['pid']['not null'] = TRUE;
$schema['comment']['fields']['status']['not null'] = TRUE;
$schema['comment']['fields']['entity_id']['not null'] = TRUE;
$schema['comment']['fields']['created']['not null'] = TRUE;
$schema['comment']['fields']['thread']['not null'] = TRUE;
$schema['comment_field_data']['fields']['created']['not null'] = TRUE;
$schema['comment_field_data']['fields']['thread']['not null'] = TRUE;
unset($schema['comment']['indexes']['field__pid']);
unset($schema['comment']['indexes']['field__entity_id']);
$schema['comment']['indexes'] += array(
unset($schema['comment_field_data']['indexes']['comment_field__pid__target_id']);
unset($schema['comment_field_data']['indexes']['comment_field__entity_id__target_id']);
$schema['comment_field_data']['indexes'] += array(
'comment__status_pid' => array('pid', 'status'),
'comment__num_new' => array(
'entity_id',
array('entity_type', 32),
'entity_type',
'comment_type',
'status',
'created',
......@@ -234,13 +240,13 @@ public function getSchema() {
),
'comment__entity_langcode' => array(
'entity_id',
array('entity_type', 32),
'entity_type',
'comment_type',
'langcode',
'default_langcode',
),
'comment__created' => array('created'),
);
$schema['comment']['foreign keys'] += array(
$schema['comment_field_data']['foreign keys'] += array(
'comment__author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
......@@ -254,8 +260,9 @@ public function getSchema() {
* {@inheritdoc}
*/
public function getUnapprovedCount() {
return $this->database->select('comment', 'c')
return $this->database->select('comment_field_data', 'c')
->condition('status', CommentInterface::NOT_PUBLISHED, '=')
->condition('default_langcode', 1)
->countQuery()
->execute()
->fetchField();
......
......@@ -34,6 +34,7 @@
* "translation" = "Drupal\comment\CommentTranslationHandler"
* },
* base_table = "comment",
* data_table = "comment_field_data",
* uri_callback = "comment_uri",
* fieldable = TRUE,
* translatable = TRUE,
......@@ -225,28 +226,33 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['subject'] = FieldDefinition::create('string')
->setLabel(t('Subject'))
->setDescription(t('The comment title or subject.'))
->setTranslatable(TRUE)
->setSetting('max_length', 64);
$fields['uid'] = FieldDefinition::create('entity_reference')
->setLabel(t('User ID'))
->setDescription(t('The user ID of the comment author.'))
->setTranslatable(TRUE)
->setSetting('target_type', 'user')
->setDefaultValue(0);
$fields['name'] = FieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t("The comment author's name."))
->setTranslatable(TRUE)
->setSetting('max_length', 60)
->setDefaultValue('')
->addConstraint('CommentName', array());
$fields['mail'] = FieldDefinition::create('email')
->setLabel(t('Email'))
->setDescription(t("The comment author's email address."));
->setDescription(t("The comment author's email address."))
->setTranslatable(TRUE);
$fields['homepage'] = FieldDefinition::create('uri')
->setLabel(t('Homepage'))
->setDescription(t("The comment author's home page address."))
->setTranslatable(TRUE)
// URIs are not length limited by RFC 2616, but we can only store 255
// characters in our comment DB schema.
->setSetting('max_length', 255);
......@@ -254,19 +260,23 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['hostname'] = FieldDefinition::create('string')
->setLabel(t('Hostname'))
->setDescription(t("The comment author's hostname."))
->setTranslatable(TRUE)
->setSetting('max_length', 128);
$fields['created'] = FieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the comment was created.'));
->setDescription(t('The time that the comment was created.'))
->setTranslatable(TRUE);
$fields['changed'] = FieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the comment was last edited.'));
->setDescription(t('The time that the comment was last edited.'))
->setTranslatable(TRUE);
$fields['status'] = FieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the comment is published.'))
->setTranslatable(TRUE)
->setDefaultValue(TRUE);
$fields['thread'] = FieldDefinition::create('string')
......@@ -276,7 +286,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['entity_type'] = FieldDefinition::create('string')
->setLabel(t('Entity type'))
->setDescription(t('The entity type to which this comment is attached.'));
->setDescription(t('The entity type to which this comment is attached.'))
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
$fields['comment_type'] = FieldDefinition::create('entity_reference')
->setLabel(t('Comment Type'))
......@@ -286,7 +297,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['field_name'] = FieldDefinition::create('string')
->setLabel(t('Comment field name'))
->setDescription(t('The field name through which this comment was added.'))
->setSetting('max_length', 32);
->setSetting('max_length', FieldConfig::NAME_MAX_LENGTH);
return $fields;
}
......
......@@ -44,31 +44,20 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
*/
public function entityQueryAlter(SelectInterface $query) {
$tables = $query->getTables();
$base_table = $tables['base_table']['alias'];
$data_table = 'comment_field_data';
if (!isset($tables['comment_field_data']['alias'])) {
// If no conditions join against the comment data table, it should be
// joined manually to allow node access processing.
$query->innerJoin($data_table, NULL, "base_table.cid = $data_table.cid AND $data_table.default_langcode = 1");
}
// The Comment module doesn't implement any proper comment access,
// and as a consequence doesn't make sure that comments cannot be viewed
// when the user doesn't have access to the node.
$node_alias = $query->innerJoin('node_field_data', 'n', '%alias.nid = ' . $base_table . '.entity_id AND ' . $base_table . ".entity_type = 'node'");
$node_alias = $query->innerJoin('node_field_data', 'n', '%alias.nid = ' . $data_table . '.entity_id AND ' . $data_table . ".entity_type = 'node'");
// Pass the query to the node access control.
$this->reAlterQuery($query, 'node_access', $node_alias);
// Alas, the comment entity exposes a bundle, but doesn't have a bundle
// column in the database. We have to alter the query ourselves to go fetch
// the bundle.
$conditions = &$query->conditions();
foreach ($conditions as $key => &$condition) {
if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'node_type') {
$condition['field'] = $node_alias . '.type';
foreach ($condition['value'] as &$value) {
if (substr($value, 0, 13) == 'comment_node_') {
$value = substr($value, 13);
}
}
break;
}
}
// Passing the query to node_query_node_access_alter() is sadly
// insufficient for nodes.
// @see SelectionEntityTypeNode::entityQueryAlter()
......
......@@ -38,8 +38,14 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
if (!empty($this->options['link_to_comment'])) {
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['entity_id'] = 'entity_id';
$this->additional_fields['entity_type'] = 'entity_type';
$this->additional_fields['entity_id'] = array(
'table' => 'comment_field_data',
'field' => 'entity_id'
);
$this->additional_fields['entity_type'] = array(
'table' => 'comment_field_data',
'field' => 'entity_type'
);
}
}
......@@ -88,7 +94,7 @@ protected function renderLink($data, ResultRow $values) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
// If there is no comment link to the entity.
elseif ($this->options['link_to_entity']) {
$entity_id = $this->getValue($values, 'entity_id');
$entity_type = $this->getValue($values, 'entity_type');
......
......@@ -42,7 +42,7 @@ public function access(AccountInterface $account) {
protected function renderLink($data, ResultRow $values) {
$status = $this->getValue($values, 'status');
// Don't show an approve link on published nodes.
// Don't show an approve link on published comment.
if ($status == CommentInterface::PUBLISHED) {
return;
}
......
......@@ -118,7 +118,7 @@ public function preRender(&$values) {
}
if ($nids) {
$result = $this->database->query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.entity_id AND c.entity_type = 'node'
$result = $this->database->query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment_field_data} c ON n.nid = c.entity_id AND c.entity_type = 'node' AND c.default_langcode = 1
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids)
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid", array(
':status' => CommentInterface::PUBLISHED,
......
......@@ -50,7 +50,7 @@ class Comment extends WizardPluginBase {
protected $filters = array(
'status' => array(
'value' => TRUE,
'table' => 'comment',
'table' => 'comment_field_data',
'field' => 'status',
'provider' => 'comment'
),
......@@ -144,7 +144,7 @@ protected function defaultDisplayOptions() {
// Add a relationship to nodes.
$display_options['relationships']['node']['id'] = 'node';
$display_options['relationships']['node']['table'] = 'comment';
$display_options['relationships']['node']['table'] = 'comment_field_data';
$display_options['relationships']['node']['field'] = 'node';
$display_options['relationships']['node']['required'] = 1;
$display_options['relationships']['node']['plugin_id'] = 'standard';
......@@ -155,7 +155,7 @@ protected function defaultDisplayOptions() {
/* Field: Comment: Title */
$display_options['fields']['subject']['id'] = 'subject';
$display_options['fields']['subject']['table'] = 'comment';
$display_options['fields']['subject']['table'] = 'comment_field_data';
$display_options['fields']['subject']['field'] = 'subject';
$display_options['fields']['subject']['provider'] = 'comment';
$display_options['fields']['subject']['label'] = '';
......
......@@ -112,11 +112,12 @@ function testCommentLanguage() {
$this->drupalPostForm(NULL, $edit, t('Save'));
// Check that comment language matches the current content language.
$cid = db_select('comment', 'c')
$cid = db_select('comment_field_data', 'c')
->fields('c', array('cid'))
->condition('entity_id', $node->id())
->condition('entity_type', 'node')
->condition('field_name', 'comment')
->condition('default_langcode', 1)
->orderBy('cid', 'DESC')
->range(0, 1)
->execute()
......
......@@ -115,10 +115,10 @@ public function testBlockDisplay() {
$this->executeView($view);
$map = array(
'comment_entity_id' => 'entity_id',
'comment_subject' => 'subject',
'comment_field_data_entity_id' => 'entity_id',
'comment_field_data_subject' => 'subject',