diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 391a255..fc859ba 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -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( diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0d3d736..668fe44 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -276,12 +276,13 @@ function comment_new_page_count($num_comments, $new_replies, ContentEntityInterf // thread with a new comment. // 1. Find all the threads with a new comment. - $unread_threads_query = db_select('comment') + $unread_threads_query = db_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_replies); @@ -300,10 +301,12 @@ function comment_new_page_count($num_comments, $new_replies, ContentEntityInterf $first_thread = substr($first_thread, 0, -1); // Find the number of the first comment of the first unread thread. - $count = db_query('SELECT COUNT(*) FROM {comment} WHERE entity_id = :entity_id + $count = db_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, @@ -578,7 +581,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); @@ -588,6 +591,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') @@ -595,12 +599,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') @@ -1019,8 +1024,8 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam function comment_get_display_ordinal($cid, FieldDefinitionInterface $field_definition) { // Count how many comments (c1) are before $cid (c2) in display order. This is // the 0-based display ordinal. - $query = db_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 = db_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', $cid); if (!user_access('administer comments')) { @@ -1039,6 +1044,8 @@ function comment_get_display_ordinal($cid, FieldDefinitionInterface $field_defin // See CommentViewBuilder. $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); return $query->execute()->fetchField(); } diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index aa6008c..52f517c 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -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', diff --git a/core/modules/comment/config/install/views.view.comments_recent.yml b/core/modules/comment/config/install/views.view.comments_recent.yml index 22a7ea9..1e20f75 100644 --- a/core/modules/comment/config/install/views.view.comments_recent.yml +++ b/core/modules/comment/config/install/views.view.comments_recent.yml @@ -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 diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index fbbdff4..24eb09a 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -179,23 +179,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() diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index f463d0a..1591aeb 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -69,10 +69,11 @@ public function updateEntityStatistics(CommentInterface $comment) { * {@inheritdoc} */ public function getMaxThread(EntityInterface $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(); @@ -82,11 +83,12 @@ public function getMaxThread(EntityInterface $comment) { * {@inheritdoc} */ public function getMaxThreadPerThread(EntityInterface $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(); @@ -96,9 +98,10 @@ public function getMaxThreadPerThread(EntityInterface $comment) { * {@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(); } @@ -111,19 +114,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; - - unset($schema['comment']['indexes']['field__pid']); - unset($schema['comment']['indexes']['field__entity_id']); - $schema['comment']['indexes'] += array( + $schema['comment_field_data']['fields']['created']['not null'] = TRUE; + $schema['comment_field_data']['fields']['thread']['not null'] = TRUE; + + 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', @@ -132,13 +132,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'), @@ -152,8 +152,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(); diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 777d92b..46ffe6b 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -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,29 +260,35 @@ 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') ->setLabel(t('Thread place')) ->setDescription(t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length.")) + ->setTranslatable(TRUE) ->setSetting('max_length', 255); $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 +298,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; } diff --git a/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php b/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php index 7a627d1..a1ebe2a 100644 --- a/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php +++ b/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php @@ -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() diff --git a/core/modules/comment/src/Plugin/views/field/Comment.php b/core/modules/comment/src/Plugin/views/field/Comment.php index df621c8..1a47a4a 100644 --- a/core/modules/comment/src/Plugin/views/field/Comment.php +++ b/core/modules/comment/src/Plugin/views/field/Comment.php @@ -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'); diff --git a/core/modules/comment/src/Plugin/views/field/LinkApprove.php b/core/modules/comment/src/Plugin/views/field/LinkApprove.php index 9fb8e00..36563f9 100644 --- a/core/modules/comment/src/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/src/Plugin/views/field/LinkApprove.php @@ -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; } diff --git a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php index 5ccf4e2..3d7e9ce 100644 --- a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php +++ b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php @@ -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, diff --git a/core/modules/comment/src/Plugin/views/wizard/Comment.php b/core/modules/comment/src/Plugin/views/wizard/Comment.php index 09fb54e..c2c4ff4 100644 --- a/core/modules/comment/src/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/src/Plugin/views/wizard/Comment.php @@ -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'] = ''; diff --git a/core/modules/comment/src/Tests/CommentLanguageTest.php b/core/modules/comment/src/Tests/CommentLanguageTest.php index d139a38..2982134 100644 --- a/core/modules/comment/src/Tests/CommentLanguageTest.php +++ b/core/modules/comment/src/Tests/CommentLanguageTest.php @@ -118,11 +118,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() diff --git a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php index b6fdce3..4cca47c 100644 --- a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php +++ b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php @@ -121,10 +121,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', 'cid' => 'cid', - 'comment_created' => 'created' + 'comment_field_data_created' => 'created' ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { diff --git a/core/modules/comment/src/Tests/Views/WizardTest.php b/core/modules/comment/src/Tests/Views/WizardTest.php index 6ced3f6..88ebe4b 100644 --- a/core/modules/comment/src/Tests/Views/WizardTest.php +++ b/core/modules/comment/src/Tests/Views/WizardTest.php @@ -88,7 +88,7 @@ public function testCommentWizard() { $this->assertEqual($row['type'], 'entity:comment'); // Check for the default filters. - $this->assertEqual($view->filter['status']->table, 'comment'); + $this->assertEqual($view->filter['status']->table, 'comment_field_data'); $this->assertEqual($view->filter['status']->field, 'status'); $this->assertTrue($view->filter['status']->value); $this->assertEqual($view->filter['status_node']->table, 'node_field_data'); @@ -96,7 +96,7 @@ public function testCommentWizard() { $this->assertTrue($view->filter['status_node']->value); // Check for the default fields. - $this->assertEqual($view->field['subject']->table, 'comment'); + $this->assertEqual($view->field['subject']->table, 'comment_field_data'); $this->assertEqual($view->field['subject']->field, 'subject'); } diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml index 2a443b5..37f34fa 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml @@ -75,14 +75,14 @@ display: field: node id: node required: true - table: comment + table: comment_field_data relationship: none group_type: group admin_label: Content fields: subject: id: subject - table: comment + table: comment_field_data field: subject label: '' alter: @@ -115,7 +115,7 @@ display: filters: status: value: '1' - table: comment + table: comment_field_data field: status id: status expose: diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml index 44245b7..be5db60 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml @@ -36,12 +36,12 @@ display: field: node id: node required: true - table: comment + table: comment_field_data provider: views fields: subject: id: subject - table: comment + table: comment_field_data field: subject plugin_id: comment label: '' diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php index 0db6520..e724bad 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php @@ -69,6 +69,8 @@ function testSettingsUI() { $edit = array( 'entity_types[comment]' => TRUE, 'settings[comment][comment_article][translatable]' => TRUE, + // Subject field translatable by default. + 'settings[comment][comment_article][fields][subject]' => FALSE, ); $this->assertSettings('comment', 'comment_article', FALSE, $edit); $xpath_err = '//div[contains(@class, "error")]'; @@ -94,13 +96,24 @@ function testSettingsUI() { 'settings[comment][comment_article][settings][language][language_show]' => TRUE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][comment_body]' => TRUE, + // Override both comment subject fields to untranslatable. + 'settings[comment][comment_article][fields][subject]' => FALSE, + 'settings[comment][comment][fields][subject]' => FALSE, ); $this->assertSettings('comment', 'comment_article', TRUE, $edit); $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['comment_body']; $this->assertTrue($definition->isTranslatable(), 'Article comment body is translatable.'); + $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['subject']; + $this->assertFalse($definition->isTranslatable(), 'Article comment subject is not translatable.'); + $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['comment_body']; $this->assertFalse($definition->isTranslatable(), 'Page comment body is not translatable.'); - $this->assertNull(content_translation_get_config('comment', 'comment_article', 'fields'), 'Configurable fields are not saved to content_translation.settings.'); + $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['subject']; + $this->assertFalse($definition->isTranslatable(), 'Page comment subject is not translatable.'); + + $settings = content_translation_get_config('comment', 'comment_article', 'fields'); + $this->assertFalse(isset($settings['comment_body']), 'Configurable fields are not saved to content_translation.settings.'); + $this->assertTrue(isset($settings['subject']), 'Base fields are saved to content_translation.settings.'); // Test that translation can be enabled for base fields. $edit = array( diff --git a/core/modules/forum/src/ForumIndexStorage.php b/core/modules/forum/src/ForumIndexStorage.php index d732806..c7fa74f 100644 --- a/core/modules/forum/src/ForumIndexStorage.php +++ b/core/modules/forum/src/ForumIndexStorage.php @@ -96,14 +96,14 @@ public function update(NodeInterface $node) { */ public function updateIndex(NodeInterface $node) { $nid = $node->id(); - $count = $this->database->query("SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status", array( + $count = $this->database->query("SELECT COUNT(cid) FROM {comment_field_data} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1", array( ':nid' => $nid, ':status' => CommentInterface::PUBLISHED, ))->fetchField(); if ($count > 0) { // Comments exist. - $last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment} WHERE entity_id = :nid AND field_name = 'comment_forum' AND entity_type = 'node' AND status = :status ORDER BY cid DESC", 0, 1, array( + $last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment_field_data} WHERE entity_id = :nid AND field_name = 'comment_forum' AND entity_type = 'node' AND status = :status AND default_langcode = 1 ORDER BY cid DESC", 0, 1, array( ':nid' => $nid, ':status' => CommentInterface::PUBLISHED, ))->fetchObject(); diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index 68b9eb8..d1c911b 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -81,7 +81,7 @@ function tracker_cron() { )) ->execute(); - $query = db_select('comment', 'c', array('target' => 'replica')); + $query = db_select('comment_field_data', 'c', array('target' => 'replica')); // Force PostgreSQL to do an implicit cast by adding 0. $query->addExpression('0 + :changed', 'changed', array(':changed' => $changed)); $query->addField('c', 'status', 'published'); @@ -92,7 +92,8 @@ function tracker_cron() { ->condition('c.entity_id', $row->nid) ->condition('c.entity_type', 'node') ->condition('c.uid', $row->uid, '<>') - ->condition('c.status', CommentInterface::PUBLISHED); + ->condition('c.status', CommentInterface::PUBLISHED) + ->condition('c.default_langcode', 1); // Insert the user-level data for the commenters (except if a commenter // is the node's author). @@ -279,7 +280,7 @@ function _tracker_calculate_changed($nid) { // @todo This should be actually filtering on the desired language and just // fall back to the default language. $changed = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1 ORDER BY changed DESC', array(':nid' => $nid), array('target' => 'replica'))->fetchField(); - $latest_comment = db_query_range("SELECT cid, changed FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND status = :status ORDER BY changed DESC", 0, 1, array( + $latest_comment = db_query_range("SELECT cid, changed FROM {comment_field_data} WHERE entity_type = 'node' AND entity_id = :nid AND status = :status AND default_langcode = 1 ORDER BY changed DESC", 0, 1, array( ':nid' => $nid, ':status' => CommentInterface::PUBLISHED, ), array('target' => 'replica'))->fetchObject(); @@ -312,7 +313,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { // Or if they have commented on the node. if (!$keep_subscription) { // Check if the user has commented at least once on the given nid. - $keep_subscription = db_query_range("SELECT COUNT(*) FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND uid = :uid AND status = :status", 0, 1, array( + $keep_subscription = db_query_range("SELECT COUNT(*) FROM {comment_field_data} WHERE entity_type = 'node' AND entity_id = :nid AND uid = :uid AND status = :status AND default_langcode = 1", 0, 1, array( ':nid' => $nid, ':uid' => $uid, ':status' => CommentInterface::PUBLISHED, diff --git a/core/modules/views/src/Tests/Handler/HandlerTest.php b/core/modules/views/src/Tests/Handler/HandlerTest.php index 14a5286..0e67316 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTest.php +++ b/core/modules/views/src/Tests/Handler/HandlerTest.php @@ -284,7 +284,7 @@ public function testSetRelationship() { // Setup a broken relationship. $view->addHandler('default', 'relationship', $this->randomName(), $this->randomName(), array(), 'broken_relationship'); // Setup a valid relationship. - $view->addHandler('default', 'relationship', 'comment', 'node', array('relationship' => 'cid'), 'valid_relationship'); + $view->addHandler('default', 'relationship', 'comment_field_data', 'node', array('relationship' => 'cid'), 'valid_relationship'); $view->initHandlers(); $field = $view->field['title']; diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_destroy.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_destroy.yml index dfe9d4c..5dfd8c9 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_destroy.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_destroy.yml @@ -155,14 +155,14 @@ display: pid: field: pid id: pid - table: comment + table: comment_field_data relationship: comment_cid plugin_id: standard provider: views uid: field: uid id: uid - table: comment + table: comment_field_data relationship: comment_cid plugin_id: standard provider: views diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml index 3b634c6..ab11335 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml @@ -45,7 +45,7 @@ display: field: node id: node required: '1' - table: comment + table: comment_field_data plugin_id: standard provider: views uid: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_handler_relationships.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_handler_relationships.yml index 9f62495..8a377d9 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_handler_relationships.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_handler_relationships.yml @@ -21,7 +21,7 @@ display: provider: views nid: id: nid - table: comment + table: comment_field_data field: node relationship: comment_cid plugin_id: standard