diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install
index dfc462b..bb25d4b 100644
--- a/core/modules/comment/comment.install
+++ b/core/modules/comment/comment.install
@@ -734,6 +734,13 @@ function comment_update_8008(&$sandbox) {
}
/**
+ * Remove the comment_block_count variable.
+ */
+function comment_update_8009() {
+ variable_del('comment_block_count');
+}
+
+/**
* @} End of "addtogroup updates-7.x-to-8.x".
* The next series of updates should start at 9000.
*/
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 2034cda..2ec1a3c 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -173,9 +173,6 @@ function comment_field_extra_fields() {
*/
function comment_theme() {
return array(
- 'comment_block' => array(
- 'variables' => array('number' => NULL),
- ),
'comment_preview' => array(
'variables' => array('comment' => NULL),
),
@@ -466,30 +463,6 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en
}
/**
- * Returns HTML for a list of recent comments.
- *
- * @ingroup themeable
- */
-function theme_comment_block($variables) {
- $items = array();
- $number = $variables['number'];
- foreach (comment_get_recent($number) as $comment) {
- $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . ' ' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))) . '';
- }
-
- if ($items) {
- $item_list = array(
- '#theme' => 'item_list',
- '#items' => $items,
- );
- return drupal_render($item_list);
- }
- else {
- return t('No comments available.');
- }
-}
-
-/**
* Implements hook_entity_view().
*/
function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode) {
diff --git a/core/modules/comment/config/views.view.comments_recent.yml b/core/modules/comment/config/views.view.comments_recent.yml
new file mode 100644
index 0000000..214d5c0
--- /dev/null
+++ b/core/modules/comment/config/views.view.comments_recent.yml
@@ -0,0 +1,217 @@
+base_field: cid
+base_table: comment
+core: 8.x
+description: ''
+status: true
+display:
+ block_1:
+ display_plugin: block
+ id: block_1
+ display_title: Block
+ position: 0
+ display_options:
+ block_description: 'Recent comments'
+ block_category: Comment
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 1
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access comments'
+ cache:
+ type: none
+ query:
+ type: views_query
+ exposed_form:
+ type: basic
+ pager:
+ type: some
+ options:
+ items_per_page: 10
+ offset: 0
+ style:
+ type: html_list
+ options:
+ grouping: { }
+ row_class: ''
+ default_row_class: true
+ row_class_special: true
+ type: ul
+ wrapper_class: item-list
+ class: ''
+ row:
+ type: fields
+ options:
+ default_field_elements: true
+ inline:
+ subject: subject
+ changed: changed
+ separator: ' '
+ hide_empty: false
+ relationships:
+ node:
+ field: node
+ id: node
+ table: comment
+ required: true
+ plugin_id: standard
+ fields:
+ subject:
+ id: subject
+ table: comment
+ field: subject
+ relationship: none
+ plugin_id: comment
+ group_type: group
+ admin_label: ''
+ label: ''
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: false
+ ellipsis: false
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: false
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ link_to_comment: true
+ link_to_node: false
+ changed:
+ id: changed
+ table: comment
+ field: changed
+ relationship: none
+ plugin_id: date
+ group_type: group
+ admin_label: ''
+ label: ''
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: false
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ date_format: 'time ago'
+ custom_date_format: ''
+ timezone: ''
+ filters:
+ status:
+ value: true
+ table: comment
+ field: status
+ id: status
+ plugin_id: boolean
+ expose:
+ operator: false
+ group: 1
+ status_node:
+ value: true
+ table: node_field_data
+ field: status
+ relationship: node
+ id: status_node
+ plugin_id: boolean
+ expose:
+ operator: false
+ group: 1
+ sorts:
+ cid:
+ id: cid
+ table: comment
+ field: cid
+ relationship: none
+ group_type: group
+ admin_label: ''
+ order: DESC
+ exposed: false
+ expose:
+ label: ''
+ plugin_id: standard
+ title: 'Recent comments'
+ empty:
+ area_text_custom:
+ id: area_text_custom
+ table: views
+ field: area_text_custom
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: ''
+ empty: true
+ content: 'No comments available.'
+ tokenize: false
+ plugin_id: text_custom
+label: 'Recent comments'
+module: views
+id: comments_recent
+tag: default
+langcode: en
diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php b/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php
deleted file mode 100644
index 10358ae..0000000
--- a/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php
+++ /dev/null
@@ -1,70 +0,0 @@
- 10,
- );
- }
-
- /**
- * Overrides \Drupal\block\BlockBase::access().
- */
- public function access() {
- return user_access('access comments');
- }
-
- /**
- * Overrides \Drupal\block\BlockBase::blockForm().
- */
- public function blockForm($form, &$form_state) {
- $form['block_count'] = array(
- '#type' => 'select',
- '#title' => t('Number of recent comments'),
- '#default_value' => $this->configuration['block_count'],
- '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),
- );
- return $form;
- }
-
- /**
- * Overrides \Drupal\block\BlockBase::blockSubmit().
- */
- public function blockSubmit($form, &$form_state) {
- $this->configuration['block_count'] = $form_state['values']['block_count'];
- }
-
- /**
- * {@inheritdoc}
- */
- public function build() {
- return array(
- '#theme' => 'comment_block',
- '#number' => $this->configuration['block_count'],
- );
- }
-
-}
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
index 61ce22b..c60e153 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
@@ -17,7 +17,7 @@ class CommentBlockTest extends CommentTestBase {
*
* @var array
*/
- public static $modules = array('block');
+ public static $modules = array('block', 'views');
function setUp() {
parent::setUp();
@@ -46,12 +46,15 @@ public static function getInfo() {
*/
function testRecentCommentBlock() {
$this->drupalLogin($this->admin_user);
- $block = $this->drupalPlaceBlock('recent_comments', array('block_count' => 2));
+ $block = $this->drupalPlaceBlock('views_block:comments_recent-block_1');
- // Add some test comments, one without a subject.
- $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $comment3 = $this->postComment($this->node, $this->randomName());
+ // Add some test comments, with and without subjects. Because the 10 newest
+ // comments should be shown by the block, we create 11 to test that behavior
+ // below.
+ for ($i = 0; $i < 11; ++$i) {
+ $subject = ($i % 2) ? $this->randomName() : '';
+ $comments[$i] = $this->postComment($this->node, $this->randomName(), $subject);
+ }
// Test that a user without the 'access comments' permission cannot see the
// block.
@@ -61,48 +64,35 @@ function testRecentCommentBlock() {
// posting a node from a node form.
cache_invalidate_tags(array('content' => TRUE));
$this->drupalGet('');
- $label = $block->label();
- $this->assertNoText($label, 'Block was not found.');
+ $this->assertNoText(t('Recent comments'));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
// Test that a user with the 'access comments' permission can see the
// block.
$this->drupalLogin($this->web_user);
$this->drupalGet('');
- $this->assertText($label, 'Block was found.');
-
- // Test the only the 2 latest comments are shown and in the proper order.
- $this->assertNoText($comment1->subject->value, 'Comment not found in block.');
- $this->assertText($comment2->subject->value, 'Comment found in block.');
- $this->assertText($comment3->comment_body->value, 'Comment found in block.');
- $this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment_body->value) < strpos($this->drupalGetContent(), $comment2->subject->value), 'Comments were ordered correctly in block.');
-
- // Set the number of recent comments to show to 10.
- $block->getPlugin()->setConfigurationValue('block_count', 10);
- $block->save();
-
- // Post an additional comment.
- $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
-
- // Test that all four comments are shown.
- $this->assertText($comment1->subject->value, 'Comment found in block.');
- $this->assertText($comment2->subject->value, 'Comment found in block.');
- $this->assertText($comment3->comment_body->value, 'Comment found in block.');
- $this->assertText($comment4->subject->value, 'Comment found in block.');
+ $this->assertText(t('Recent comments'));
+
+ // Test the only the 10 latest comments are shown and in the proper order.
+ $this->assertNoText($comments[0]->subject->value, 'Comment 11 not found in block.');
+ for ($i = 1; $i < 11; $i++) {
+ $this->assertText($comments[$i]->subject->value, format_string('Comment @number found in block.', array('@number' => 11 - $i)));
+ if ($i > 1) {
+ $previous_position = $position;
+ $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value);
+ $this->assertTrue($position < $previous_position, format_string('Comment @a appears before comment @b', array('@a' => 11 - $i, '@b' => 12 - $i)));
+ }
+ $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value);
+ }
// Test that links to comments work when comments are across pages.
$this->setCommentsPerPage(1);
- $this->drupalGet('');
- $this->clickLink($comment1->subject->value);
- $this->assertText($comment1->subject->value, 'Comment link goes to correct page.');
- $this->drupalGet('');
- $this->clickLink($comment2->subject->value);
- $this->assertText($comment2->subject->value, 'Comment link goes to correct page.');
- $this->clickLink($comment4->subject->value);
- $this->assertText($comment4->subject->value, 'Comment link goes to correct page.');
- // Check that when viewing a comment page from a link to the comment, that
- // rel="canonical" is added to the head of the document.
- $this->assertRaw('clickLink($comments[$i]->subject->value);
+ $this->assertText($comments[$i]->subject->value, 'Comment link goes to correct page.');
+ $this->assertRaw('