diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index 6276f95..3a91ad6 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Field\FieldDefinitionInterface; @@ -123,8 +124,7 @@ public function viewElements(FieldItemListInterface $items) { $elements = array(); $url = NULL; if ($this->getSetting('link_to_entity')) { - // For the default revision this falls back to 'canonical' - $url = $items->getEntity()->urlInfo('revision'); + $url = $this->getEntityUrl($items->getEntity()); } foreach ($items as $delta => $item) { @@ -158,4 +158,18 @@ protected function viewValue(FieldItemInterface $item) { return nl2br(SafeMarkup::checkPlain($item->value)); } + /** + * Gets the URI elements of the entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity object. + * + * @return \Drupal\Core\Url + * The URI elements of the entity. + */ + protected function getEntityUrl(EntityInterface $entity) { + // For the default revision this falls back to 'canonical' + return $entity->urlInfo('revision'); + } + } diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml index 967cb3f..91c81bb 100644 --- a/core/modules/comment/comment.routing.yml +++ b/core/modules/comment/comment.routing.yml @@ -2,7 +2,7 @@ comment.admin: path: '/admin/content/comment' defaults: _title: 'Comments' - _controller: '\Drupal\comment\Controller\AdminController::adminPage' + _form: '\Drupal\comment\Form\CommentAdminOverview' type: 'new' requirements: _permission: 'administer comments' @@ -11,7 +11,7 @@ comment.admin_approval: path: '/admin/content/comment/approval' defaults: _title: 'Unapproved comments' - _controller: '\Drupal\comment\Controller\AdminController::adminPage' + _form: '\Drupal\comment\Form\CommentAdminOverview' type: 'approval' requirements: _permission: 'administer comments' @@ -50,6 +50,14 @@ entity.comment.delete_form: requirements: _entity_access: 'comment.delete' +comment.multiple_delete_confirm: + path: '/admin/content/comment/delete' + defaults: + _title: 'Delete' + _form: '\Drupal\comment\Form\ConfirmDeleteMultiple' + requirements: + _permission: 'administer comments' + comment.reply: path: '/comment/reply/{entity_type}/{entity}/{field_name}/{pid}' defaults: diff --git a/core/modules/comment/config/install/system.action.comment_delete_action.yml b/core/modules/comment/config/install/system.action.comment_delete_action.yml new file mode 100644 index 0000000..89dd7c9 --- /dev/null +++ b/core/modules/comment/config/install/system.action.comment_delete_action.yml @@ -0,0 +1,9 @@ +id: comment_delete_action +label: 'Delete comment' +status: true +langcode: en +type: comment +plugin: comment_delete_action +dependencies: + module: + - comment diff --git a/core/modules/comment/config/optional/views.view.comment.yml b/core/modules/comment/config/optional/views.view.comment.yml new file mode 100644 index 0000000..56c4de3 --- /dev/null +++ b/core/modules/comment/config/optional/views.view.comment.yml @@ -0,0 +1,994 @@ +langcode: en +status: true +dependencies: + module: + - comment + - user +id: comment +label: Comments +module: comment +description: 'Find and manage comments.' +tag: '' +base_table: comment_field_data +base_field: cid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'administer comments' + cache: + type: none + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: full + options: + items_per_page: 50 + offset: 0 + id: 0 + total_pages: null + tags: + previous: '‹ previous' + next: 'next ›' + first: '« first' + last: 'last »' + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + quantity: 9 + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: true + override: true + sticky: true + caption: '' + summary: '' + description: '' + columns: + comment_bulk_form: comment_bulk_form + subject: subject + name: name + commented_entity_label: commented_entity_label + changed: changed + operations: operations + info: + comment_bulk_form: + align: '' + separator: '' + empty_column: false + responsive: '' + subject: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + name: + sortable: true + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: priority-medium + commented_entity_label: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + changed: + sortable: true + default_sort_order: desc + align: '' + separator: '' + empty_column: false + responsive: priority-low + operations: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + default: changed + empty_table: true + row: + type: fields + fields: + comment_bulk_form: + id: comment_bulk_form + table: comment + field: comment_bulk_form + relationship: none + 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: 0 + 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 + action_title: 'Update Options' + include_exclude: include + selected_actions: + - comment_delete_action + - comment_unpublish_action + plugin_id: comment_bulk_form + entity_type: comment + subject: + id: subject + table: comment_field_data + field: subject + relationship: none + group_type: group + admin_label: '' + label: Subject + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: comment_permalink + settings: + link_to_entity: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: comment + entity_field: subject + plugin_id: field + name: + id: name + table: comment_field_data + field: name + relationship: none + group_type: group + admin_label: '' + label: Author + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: comment_username + settings: { } + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: comment + entity_field: name + plugin_id: field + commented_entity_label: + id: commented_entity_label + table: comment + field: commented_entity_label + relationship: none + group_type: group + admin_label: '' + label: 'Posted in' + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + link_to_entity: true + entity_type: comment + plugin_id: commented_entity_label + changed: + id: changed + table: comment_field_data + field: changed + relationship: none + group_type: group + admin_label: '' + label: Updated + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + date_format: short + custom_date_format: '' + timezone: '' + entity_type: comment + entity_field: changed + plugin_id: date + operations: + id: operations + table: comment + field: operations + relationship: none + group_type: group + admin_label: '' + label: Operations + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + destination: true + entity_type: comment + plugin_id: entity_operations + filters: + status: + id: status + table: comment_field_data + field: status + relationship: none + group_type: group + admin_label: '' + operator: '=' + value: true + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + entity_type: comment + entity_field: status + plugin_id: boolean + sorts: + changed: + id: changed + table: comment_field_data + field: changed + relationship: none + group_type: group + admin_label: '' + order: DESC + exposed: false + expose: + label: '' + granularity: second + entity_type: comment + entity_field: changed + plugin_id: date + title: Comments + header: { } + footer: { } + empty: + area_text_custom: + id: area_text_custom + table: views + field: area_text_custom + relationship: none + group_type: group + admin_label: '' + empty: true + tokenize: false + content: 'No comments available.' + plugin_id: text_custom + arguments: { } + display_extenders: { } + use_more: false + use_more_always: true + use_more_text: more + use_ajax: false + hide_attachment_summary: false + show_admin_links: true + group_by: false + css_class: '' + cache_metadata: + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - 'url.query_args.pagers:0' + - 'url.query_args:order' + - 'url.query_args:sort' + cacheable: false + page_1: + display_plugin: page + id: page_1 + display_title: 'Published Comments' + position: 1 + display_options: + path: admin/content/comment + menu: + type: tab + title: Comments + description: 'Comments published' + parent: '' + weight: 0 + context: '0' + menu_name: admin + display_description: '' + display_extenders: { } + exposed_block: false + display_comment: '' + cache_metadata: + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - 'url.query_args.pagers:0' + - 'url.query_args:order' + - 'url.query_args:sort' + cacheable: false + page_2: + display_plugin: page + id: page_2 + display_title: 'Unapproved Comments' + position: 2 + display_options: + path: admin/content/comment/approval + menu: + type: tab + title: 'Unapproved comments' + description: 'Comments unapproved' + parent: '' + weight: 1 + context: '0' + menu_name: admin + display_description: '' + filters: + status: + id: status + table: comment_field_data + field: status + relationship: none + group_type: group + admin_label: '' + operator: '=' + value: false + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + entity_type: comment + entity_field: status + plugin_id: boolean + defaults: + filters: false + filter_groups: false + fields: false + display_extenders: { } + fields: + comment_bulk_form: + id: comment_bulk_form + table: comment + field: comment_bulk_form + relationship: none + 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: 0 + 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 + action_title: 'Update Options' + include_exclude: include + selected_actions: + - comment_delete_action + - comment_publish_action + plugin_id: comment_bulk_form + entity_type: comment + subject: + id: subject + table: comment_field_data + field: subject + relationship: none + group_type: group + admin_label: '' + label: Subject + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: comment_permalink + settings: + link_to_entity: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: comment + entity_field: subject + plugin_id: field + name: + id: name + table: comment_field_data + field: name + relationship: none + group_type: group + admin_label: '' + label: Author + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: comment_username + settings: { } + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: comment + entity_field: name + plugin_id: field + commented_entity_label: + id: commented_entity_label + table: comment + field: commented_entity_label + relationship: none + group_type: group + admin_label: '' + label: 'Posted in' + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + link_to_entity: true + entity_type: comment + plugin_id: commented_entity_label + changed: + id: changed + table: comment_field_data + field: changed + relationship: none + group_type: group + admin_label: '' + label: Updated + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + date_format: short + custom_date_format: '' + timezone: '' + entity_type: comment + entity_field: changed + plugin_id: date + operations: + id: operations + table: comment + field: operations + relationship: none + group_type: group + admin_label: '' + label: Operations + 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: 0 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + destination: true + entity_type: comment + plugin_id: entity_operations + cache_metadata: + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - 'url.query_args.pagers:0' + - 'url.query_args:order' + - 'url.query_args:sort' + cacheable: false diff --git a/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml index d9f5a77..be6ba5e 100644 --- a/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -102,3 +102,10 @@ field.field_settings.comment: preview: type: integer label: 'Preview comment' + +field.formatter.settings.comment_permalink: + type: field.formatter.settings.string + +action.configuration.comment_delete_action: + type: action_configuration_default + label: 'Delete comment configuration' diff --git a/core/modules/comment/config/schema/comment.views.schema.yml b/core/modules/comment/config/schema/comment.views.schema.yml index 606af82..9b59207 100644 --- a/core/modules/comment/config/schema/comment.views.schema.yml +++ b/core/modules/comment/config/schema/comment.views.schema.yml @@ -16,6 +16,18 @@ views.field.comment_entity_link: type: boolean label: 'Show teaser-style link' +views.field.comment_bulk_form: + type: views_field_bulk_form + label: 'Comment bulk form' + +views.field.commented_entity_label: + type: views_field + label: 'Commented entity label' + mapping: + link_to_entity: + type: boolean + label: 'Link to entity' + views.field.comment_last_timestamp: type: views.field.date label: 'Last comment date' diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index c70f77f..91c97a3 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -27,6 +27,7 @@ public function getViewsData() { $data['comment_field_data']['subject']['title'] = t('Title'); $data['comment_field_data']['subject']['help'] = t('The title of the comment.'); + $data['comment_field_data']['subject']['field']['default_formatter'] = 'comment_permalink'; $data['comment_field_data']['name']['title'] = t('Author'); $data['comment_field_data']['name']['help'] = t("The name of the comment's author. Can be rendered as a link to the author's homepage."); @@ -118,6 +119,22 @@ public function getViewsData() { ), ); + $data['comment']['commented_entity_label'] = array( + 'title' => t('Label of commented entity'), + 'help' => t('Provide a label of commented entity.'), + 'field' => array( + 'id' => 'commented_entity_label', + ), + ); + + $data['comment']['comment_bulk_form'] = array( + 'title' => t('Comment operations bulk form'), + 'help' => t('Add a form element that lets you run operations on multiple comments.'), + 'field' => array( + 'id' => 'comment_bulk_form', + ), + ); + $data['comment_field_data']['thread']['field'] = array( 'title' => t('Depth'), 'help' => t('Display the depth of the comment if it is threaded.'), diff --git a/core/modules/comment/src/Controller/AdminController.php b/core/modules/comment/src/Controller/AdminController.php deleted file mode 100644 index 4c1592f..0000000 --- a/core/modules/comment/src/Controller/AdminController.php +++ /dev/null @@ -1,67 +0,0 @@ -get('form_builder') - ); - } - - /** - * Constructs an AdminController object. - * - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - */ - public function __construct(FormBuilderInterface $form_builder) { - $this->formBuilder = $form_builder; - } - - /** - * Presents an administrative comment listing. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request of the page. - * @param string $type - * The type of the overview form ('approval' or 'new') default to 'new'. - * - * @return array - * Then comment multiple delete confirmation form or the comments overview - * administration form. - */ - public function adminPage(Request $request, $type = 'new') { - if ($request->request->get('operation') == 'delete' && $request->request->get('comments')) { - return $this->formBuilder->getForm('\Drupal\comment\Form\ConfirmDeleteMultiple', $request); - } - else { - return $this->formBuilder->getForm('\Drupal\comment\Form\CommentAdminOverview', $type); - } - } - -} diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index bd3fbfc..5525765 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -35,6 +35,7 @@ * "default" = "Drupal\comment\CommentForm", * "delete" = "Drupal\comment\Form\DeleteForm" * }, + * "list_builder" = "Drupal\Core\Entity\EntityListBuilder", * "translation" = "Drupal\comment\CommentTranslationHandler" * }, * base_table = "comment", diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index 008e0bb..070f452 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -8,7 +8,6 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentInterface; -use Drupal\comment\CommentStorageInterface; use Drupal\Component\Utility\Unicode; use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityManagerInterface; @@ -16,6 +15,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\user\PrivateTempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -52,22 +52,30 @@ class CommentAdminOverview extends FormBase { protected $moduleHandler; /** + * The tempstore factory. + * + * @var \Drupal\user\PrivateTempStoreFactory + */ + protected $tempStoreFactory; + + /** * Creates a CommentAdminOverview form. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. - * @param \Drupal\comment\CommentStorageInterface $comment_storage - * The comment storage. * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory + * The tempstore factory. */ - public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManagerInterface $entity_manager, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler, PrivateTempStoreFactory $temp_store_factory) { $this->entityManager = $entity_manager; - $this->commentStorage = $comment_storage; + $this->commentStorage = $entity_manager->getStorage('comment'); $this->dateFormatter = $date_formatter; $this->moduleHandler = $module_handler; + $this->tempStoreFactory = $temp_store_factory; } /** @@ -76,9 +84,9 @@ public function __construct(EntityManagerInterface $entity_manager, CommentStora public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('entity.manager')->getStorage('comment'), $container->get('date.formatter'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('user.private_tempstore') ); } @@ -262,23 +270,27 @@ public function validateForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { $operation = $form_state->getValue('operation'); $cids = $form_state->getValue('comments'); - - foreach ($cids as $cid) { - // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple - // see \Drupal\comment\Controller\AdminController::adminPage(). - if ($operation == 'unpublish') { - $comment = $this->commentStorage->load($cid); - $comment->setPublished(FALSE); - $comment->save(); - } - elseif ($operation == 'publish') { - $comment = $this->commentStorage->load($cid); - $comment->setPublished(TRUE); + /** @var \Drupal\comment\CommentInterface[] $comments */ + $comments = $this->commentStorage->loadMultiple($cids); + if ($operation != 'delete') { + foreach ($comments as $comment) { + if ($operation == 'unpublish') { + $comment->setPublished(FALSE); + } + elseif ($operation == 'publish') { + $comment->setPublished(TRUE); + } $comment->save(); } + drupal_set_message($this->t('The update has been performed.')); + $form_state->setRedirect('comment.admin'); + } + else { + $this->tempStoreFactory + ->get('comment_multiple_delete_confirm') + ->set($this->currentUser()->id(), $comments); + $form_state->setRedirect('comment.multiple_delete_confirm'); } - drupal_set_message($this->t('The update has been performed.')); - $form_state->setRedirect('comment.admin'); } } diff --git a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php index 666b555..9d990f4 100644 --- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentStorageInterface; +use Drupal\user\PrivateTempStoreFactory; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; @@ -20,6 +21,13 @@ class ConfirmDeleteMultiple extends ConfirmFormBase { /** + * The tempstore factory. + * + * @var \Drupal\user\PrivateTempStoreFactory + */ + protected $tempStoreFactory; + + /** * The comment storage. * * @var \Drupal\comment\CommentStorageInterface @@ -38,9 +46,12 @@ class ConfirmDeleteMultiple extends ConfirmFormBase { * * @param \Drupal\comment\CommentStorageInterface $comment_storage * The comment storage. + * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory + * The tempstore factory. */ - public function __construct(CommentStorageInterface $comment_storage) { + public function __construct(CommentStorageInterface $comment_storage, PrivateTempStoreFactory $temp_store_factory) { $this->commentStorage = $comment_storage; + $this->tempStoreFactory = $temp_store_factory; } /** @@ -48,7 +59,8 @@ public function __construct(CommentStorageInterface $comment_storage) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('comment') + $container->get('entity.manager')->getStorage('comment'), + $container->get('user.private_tempstore') ); } @@ -63,7 +75,7 @@ public function getFormId() { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete these comments and all their children?'); + return $this->formatPlural(count($this->comments), 'Are you sure you want to delete this comment and all its children?', 'Are you sure you want to delete these comments and all their children?'); } /** @@ -77,23 +89,24 @@ public function getCancelUrl() { * {@inheritdoc} */ public function getConfirmText() { - return $this->t('Delete comments'); + return $this->t('Delete'); } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - $edit = $form_state->getUserInput(); + $this->comments = $this->tempStoreFactory->get('comment_multiple_delete_confirm')->get($this->currentUser()->id()); + if (empty($this->comments)) { + return $this->redirect('comment.admin'); + } $form['comments'] = array( '#prefix' => '