- if ($form_state->getValue('confirm')) {
- $this->commentStorage->delete($this->comments);
- $count = count($form_state->getValue('comments'));
- $this->logger('comment')->notice('Deleted @count comments.', ['@count' => $count]);
- drupal_set_message($this->formatPlural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
+ if ($form_state->getValue('confirm') && !empty($this->commentInfo)) {
+ $total_count = 0;
+ $delete_comments = [];
+ /** @var \Drupal\Core\Entity\ContentEntityInterface[][] $delete_translations */
+ $delete_translations = [];
+ /** @var \Drupal\comment\CommentInterface[] $comments */
+ $comments = $this->commentStorage->loadMultiple(array_keys($this->commentInfo));
+
+ foreach ($this->commentInfo as $id => $langcodes) {
+ foreach ($langcodes as $langcode) {
+ $comment = $comments[$id]->getTranslation($langcode);
+ if ($comment->isDefaultTranslation()) {
+ $delete_comments[$id] = $comment;
+ unset($delete_translations[$id]);
+ $total_count += count($comment->getTranslationLanguages());
+ }
+ elseif (!isset($delete_comments[$id])) {
+ $delete_translations[$id][] = $comment;
+ }
+ }
+ }
+
+ if ($delete_comments) {
+ $this->commentStorage->delete($delete_comments);
+ $this->logger('content')->notice('Deleted @count comments.', ['@count' => count($delete_comments)]);
+ }
+
+ if ($delete_translations) {
+ $count = 0;
+ foreach ($delete_translations as $id => $translations) {
+ $comment = $comments[$id]->getUntranslated();
+ foreach ($translations as $translation) {
+ $comment->removeTranslation($translation->language()->getId());
+ }
+ $comment->save();
+ $count += count($translations);
+ }
+ if ($count) {
+ $total_count += $count;
+ $this->logger('content')->notice('Deleted @count comment translations.', ['@count' => $count]);
+ }
+ }
+
+ if ($total_count) {
+ drupal_set_message($this->formatPlural($total_count, 'Deleted 1 comment.', 'Deleted @count comments.'));
+ }
+
+ $this->tempStoreFactory->get('comment_multiple_delete_confirm')->delete($this->currentUser()->id());