diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9895b1f..ab77162 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1837,6 +1837,12 @@ function comment_action_info() { 'configurable' => FALSE, 'triggers' => array('comment_insert', 'comment_update'), ), + 'comment_delete_action' => array( + 'label' => t('Delete comment'), + 'type' => 'comment', + 'configurable' => FALSE, + 'triggers' => array('comment_delete'), + ), ); } @@ -1961,6 +1967,20 @@ function comment_save_action(Comment $comment) { } /** + * Deletes a comment. + * + * @param Drupal\comment\Comment $comment + * + * @ingroup actions + */ +function comment_delete_action(Comment $comment) { + $subject = $comment->subject->value; + comment_delete($comment->cid->value); + cache_invalidate_tags(array('content' => TRUE)); + watchdog('action', 'Deleted comment %subject.', array('%title' => $subject)); +} + +/** * Implements hook_ranking(). */ function comment_ranking() { diff --git a/core/modules/comment/config/views.view.comments.yml b/core/modules/comment/config/views.view.comments.yml old mode 100755 new mode 100644 index 3b4628a..a7c42ec --- a/core/modules/comment/config/views.view.comments.yml +++ b/core/modules/comment/config/views.view.comments.yml @@ -4,65 +4,123 @@ core: 8.x description: '' status: '1' display: - page_2: - display_plugin: page - id: page_2 - display_title: 'Unapproved comments' + default: + display_plugin: default + id: default + display_title: Master position: '' display_options: - display_description: 'Comments pending to approval' - path: admin/content/comment/approval - menu: - type: tab - title: 'Unapproved comments' - description: '' - name: admin - weight: '0' - context: '0' - filters: - status: - id: status + access: + type: perm + options: + perm: 'administer comments' + cache: + type: none + options: { } + query: + type: views_query + options: + disable_sql_rewrite: '0' + distinct: '0' + slave: '0' + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: '0' + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: '1' + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: full + options: + items_per_page: '50' + offset: '0' + id: '0' + total_pages: '' + expose: + items_per_page: '0' + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 20, 40, 60' + items_per_page_options_all: '0' + items_per_page_options_all_label: '- All -' + offset: '0' + offset_label: Offset + tags: + previous: '‹ previous' + next: 'next ›' + first: '« first' + last: 'last »' + quantity: '9' + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: '1' + row_class_special: '1' + override: '1' + sticky: '0' + summary: '' + columns: + action_bulk_form: action_bulk_form + subject: subject + name: name + title: title + changed: changed + info: + action_bulk_form: + sortable: '0' + default_sort_order: asc + align: '' + separator: '' + empty_column: '0' + responsive: '' + subject: + sortable: '1' + default_sort_order: asc + align: '' + separator: '' + empty_column: '0' + responsive: '' + name: + sortable: '1' + default_sort_order: asc + align: '' + separator: '' + empty_column: '0' + responsive: '' + title: + sortable: '1' + default_sort_order: asc + align: '' + separator: '' + empty_column: '0' + responsive: '' + changed: + sortable: '1' + default_sort_order: desc + align: '' + separator: '' + empty_column: '0' + responsive: '' + default: changed + empty_table: '1' + row: + type: fields + relationships: + nid: + id: nid table: comment - field: status + field: nid + required: '1' relationship: none group_type: group - admin_label: '' - operator: '=' - value: '0' - group: '1' - exposed: '0' - expose: - operator_id: '0' - label: '' - description: '' - use_operator: '0' - operator: '0' - identifier: '' - required: '0' - remember: '0' - multiple: '0' - remember_roles: - authenticated: authenticated - is_grouped: '0' - group_info: - label: '' - description: '' - identifier: '' - optional: '1' - widget: select - multiple: '0' - remember: '0' - default_group: All - default_group_multiple: { } - group_items: { } - defaults: - filters: '0' - filter_groups: '0' - fields: '0' - filter_groups: - operator: AND - groups: - 1: AND + admin_label: Content fields: action_bulk_form: id: action_bulk_form @@ -114,7 +172,7 @@ display: hide_alter_empty: '1' include_exclude: include selected_actions: - comment_publish_action: comment_publish_action + comment_unpublish_action: comment_unpublish_action plugin_id: action_bulk_form subject: id: subject @@ -218,7 +276,7 @@ display: plugin_id: comment_username title: id: title - table: node + table: node_field_data field: title relationship: nid group_type: group @@ -318,21 +376,87 @@ display: custom_date_format: '' timezone: '' plugin_id: date - page_1: + filters: + status: + id: status + table: comment + field: status + relationship: none + group_type: group + admin_label: '' + operator: '=' + value: '0' + group: '1' + exposed: '0' + expose: + operator_id: '0' + label: '' + description: '' + use_operator: '0' + operator: '0' + identifier: '' + required: '0' + remember: '0' + multiple: '0' + remember_roles: + authenticated: authenticated + is_grouped: '0' + group_info: + label: '' + description: '' + identifier: '' + optional: '1' + widget: select + multiple: '0' + remember: '0' + default_group: All + default_group_multiple: { } + group_items: { } + sorts: + created: + id: created + table: comment + field: created + order: DESC + relationship: none + group_type: group + admin_label: '' + exposed: '0' + expose: + label: '' + granularity: second + title: Comments + header: { } + footer: { } + empty: + area: + id: area + table: views + field: area + relationship: none + group_type: group + admin_label: '' + empty: '1' + content: "

No comments available.

\n" + format: basic_html + tokenize: '0' + plugin_id: text + arguments: { } + page_2: display_plugin: page - id: page_1 - display_title: Comments + id: page_2 + display_title: 'Unapproved comments' position: '' display_options: - path: admin/content/comment + display_description: 'Comments pending to approval' + path: admin/content/comment/approval menu: type: tab - title: Comments - description: 'Comments published' + title: 'Unapproved comments' + description: '' name: admin weight: '0' context: '0' - display_description: '' filters: status: id: status @@ -342,7 +466,7 @@ display: group_type: group admin_label: '' operator: '=' - value: '1' + value: '0' group: '1' exposed: '0' expose: @@ -426,7 +550,7 @@ display: hide_empty: '0' empty_zero: '0' hide_alter_empty: '1' - include_exclude: exclude + include_exclude: include selected_actions: comment_publish_action: comment_publish_action plugin_id: action_bulk_form @@ -532,7 +656,7 @@ display: plugin_id: comment_username title: id: title - table: node + table: node_field_data field: title relationship: nid group_type: group @@ -632,115 +756,65 @@ display: custom_date_format: '' timezone: '' plugin_id: date - default: - display_plugin: default - id: default - display_title: Master + page_1: + display_plugin: page + id: page_1 + display_title: Comments position: '' display_options: - access: - type: perm - options: - perm: 'administer comments' - cache: - type: none - options: { } - query: - type: views_query - options: - disable_sql_rewrite: '0' - distinct: '0' - slave: '0' - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: '0' - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: '1' - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: full - options: - items_per_page: '50' - offset: '0' - id: '0' - total_pages: '' - expose: - items_per_page: '0' - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 20, 40, 60' - items_per_page_options_all: '0' - items_per_page_options_all_label: '- All -' - offset: '0' - offset_label: Offset - tags: - previous: '‹ previous' - next: 'next ›' - first: '« first' - last: 'last »' - quantity: '9' - style: - type: table - options: - grouping: { } - row_class: '' - default_row_class: '1' - row_class_special: '1' - override: '1' - sticky: '0' - summary: '' - columns: - subject: subject - name: name - changed: changed - title: title - info: - subject: - sortable: '1' - default_sort_order: asc - align: '' - separator: '' - empty_column: '0' - responsive: '' - name: - sortable: '1' - default_sort_order: asc - align: '' - separator: '' - empty_column: '0' - responsive: '' - changed: - sortable: '1' - default_sort_order: desc - align: '' - separator: '' - empty_column: '0' - responsive: '' - title: - sortable: '1' - default_sort_order: asc - align: '' - separator: '' - empty_column: '0' - responsive: '' - default: changed - empty_table: '0' - row: - type: fields - relationships: - nid: - id: nid + path: admin/content/comment/new + menu: + type: tab + title: 'Published comments' + description: 'Comments published' + name: admin + weight: '-10' + context: '0' + display_description: '' + filters: + status: + id: status table: comment - field: nid - required: '1' + field: status relationship: none group_type: group - admin_label: Content + admin_label: '' + operator: '=' + value: '1' + group: '1' + exposed: '0' + expose: + operator_id: '0' + label: '' + description: '' + use_operator: '0' + operator: '0' + identifier: '' + required: '0' + remember: '0' + multiple: '0' + remember_roles: + authenticated: authenticated + is_grouped: '0' + group_info: + label: '' + description: '' + identifier: '' + optional: '1' + widget: select + multiple: '0' + remember: '0' + default_group: All + default_group_multiple: { } + group_items: { } + defaults: + filters: '0' + filter_groups: '0' + fields: '0' + filter_groups: + operator: AND + groups: + 1: AND fields: action_bulk_form: id: action_bulk_form @@ -790,7 +864,7 @@ display: hide_empty: '0' empty_zero: '0' hide_alter_empty: '1' - include_exclude: exclude + include_exclude: include selected_actions: comment_unpublish_action: comment_unpublish_action plugin_id: action_bulk_form @@ -896,7 +970,7 @@ display: plugin_id: comment_username title: id: title - table: node + table: node_field_data field: title relationship: nid group_type: group @@ -996,72 +1070,6 @@ display: custom_date_format: '' timezone: '' plugin_id: date - filters: - status: - id: status - table: comment - field: status - relationship: none - group_type: group - admin_label: '' - operator: '=' - value: '0' - group: '1' - exposed: '0' - expose: - operator_id: '0' - label: '' - description: '' - use_operator: '0' - operator: '0' - identifier: '' - required: '0' - remember: '0' - multiple: '0' - remember_roles: - authenticated: authenticated - is_grouped: '0' - group_info: - label: '' - description: '' - identifier: '' - optional: '1' - widget: select - multiple: '0' - remember: '0' - default_group: All - default_group_multiple: { } - group_items: { } - sorts: - created: - id: created - table: comment - field: created - order: DESC - relationship: none - group_type: group - admin_label: '' - exposed: '0' - expose: - label: '' - granularity: second - title: Comments - header: { } - footer: { } - empty: - area: - id: area - table: views - field: area - relationship: none - group_type: group - admin_label: '' - empty: '1' - content: "

No comments available.

\n" - format: basic_html - tokenize: '0' - plugin_id: text - arguments: { } label: Comments module: views id: comments diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php index a942d7c..0b0282a 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -83,6 +83,23 @@ function testCommentUnpublishByKeyword() { } /** + * Tests comment delete action. + */ + function testCommentDeleteAction() { + $this->drupalLogin($this->web_user); + $comment_text = $this->randomName(); + $subject = $this->randomName(); + $comment = $this->postComment($this->node, $comment_text, $subject); + + // Delete a comment. + comment_delete_action($comment); + $comment = comment_load($comment->cid->value); + $this->assertTrue(empty($comment), 'Comment was deleted'); + $this->assertWatchdogMessage('Deleted comment %subject.', array('%subject' => $subject), 'Found watchdog message'); + $this->clearWatchdog(); + } + + /** * Verifies that a watchdog message has been entered. * * @param $watchdog_message