From dc2ef49ec3826cdff5c3abb2442fdd0db22f2f5c Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Thu, 2 Jan 2014 12:28:04 -0800
Subject: [PATCH] Issue #1978904 by jibran, andypost, h3rj4n, larowlan,
 shanethehat, pcambra, Xano: Convert comment_admin() to a Controller.

---
 core/modules/comment/comment.admin.inc        | 234 --------------
 core/modules/comment/comment.routing.yml      |   4 +-
 .../comment/Controller/AdminController.php    |  42 ++-
 .../comment/Controller/CommentController.php  |  39 +--
 .../comment/Form/CommentAdminOverview.php     | 305 ++++++++++++++++++
 .../comment/Form/ConfirmDeleteMultiple.php    |  11 +-
 .../Drupal/comment/Tests/CommentAdminTest.php |   6 +
 7 files changed, 368 insertions(+), 273 deletions(-)
 delete mode 100644 core/modules/comment/comment.admin.inc
 create mode 100644 core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php

diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc
deleted file mode 100644
index 99bb6b0a31f2..000000000000
--- a/core/modules/comment/comment.admin.inc
+++ /dev/null
@@ -1,234 +0,0 @@
-<?php
-
-/**
- * @file
- * Admin page callbacks for the Comment module.
- */
-
-use Drupal\comment\CommentInterface;
-
-/**
- * Page callback: Presents an administrative comment listing.
- *
- * @param $type
- *   The type of the overview form ('approval' or 'new'). See
- *   comment_admin_overview() for details.
- *
- * @see comment_menu()
- * @see comment_multiple_delete_confirm()
- *
- * @deprecated Use \Drupal\comment\Controller\CommentController::adminPage()
- */
-function comment_admin($type = 'new') {
-  $request = \Drupal::request();
-  $edit = $request->request->all();
-
-  if (isset($edit['operation']) && ($edit['operation'] == 'delete') && isset($edit['comments']) && $edit['comments']) {
-    return drupal_get_form('Drupal\comment\Form\ConfirmDeleteMultiple');
-  }
-  else {
-    return drupal_get_form('comment_admin_overview', $type);
-  }
-}
-
-/**
- * Form constructor for the comment overview administration form.
- *
- * @param $arg
- *   The type of overview form ('approval' or 'new').
- *
- * @ingroup forms
- * @see comment_admin()
- * @see comment_admin_overview_validate()
- * @see comment_admin_overview_submit()
- * @see theme_comment_admin_overview()
- */
-function comment_admin_overview($form, &$form_state, $arg) {
-  // Build an 'Update options' form.
-  $form['options'] = array(
-    '#type' => 'details',
-    '#title' => t('Update options'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  if ($arg == 'approval') {
-    $options['publish'] = t('Publish the selected comments');
-  }
-  else {
-    $options['unpublish'] = t('Unpublish the selected comments');
-  }
-  $options['delete'] = t('Delete the selected comments');
-
-  $form['options']['operation'] = array(
-    '#type' => 'select',
-    '#title' => t('Action'),
-    '#title_display' => 'invisible',
-    '#options' => $options,
-    '#default_value' => 'publish',
-  );
-  $form['options']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Update'),
-  );
-
-  // Load the comments that need to be displayed.
-  $status = ($arg == 'approval') ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED;
-  $header = array(
-    'subject' => array('data' => t('Subject'), 'field' => 'subject'),
-    'author' => array('data' => t('Author'), 'field' => 'name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
-    'posted_in' => array('data' => t('Posted in'), 'field' => 'node_title', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
-    'changed' => array('data' => t('Updated'), 'field' => 'c.changed', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
-    'operations' => t('Operations'),
-  );
-
-  $query = db_select('comment', 'c')
-    ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
-    ->extend('Drupal\Core\Database\Query\TableSortExtender');
-  if (\Drupal::moduleHandler()->moduleExists('node')) {
-    // Special case to ensure node access works.
-    $query->leftJoin('node_field_data', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'");
-    $query->addTag('node_access');
-  }
-  $result = $query
-    ->fields('c', array('cid', 'subject', 'name', 'changed', 'entity_id', 'entity_type', 'field_id'))
-    ->condition('c.status', $status)
-    ->limit(50)
-    ->orderByHeader($header)
-    ->execute();
-
-  $cids = array();
-  $entity_ids = array();
-  $entities = array();
-
-  // We collect entities grouped by entity_type so we can load them and use
-  // their labels.
-  foreach ($result as $row) {
-    $entity_ids[$row->entity_type][] = $row->entity_id;
-    $cids[] = $row->cid;
-  }
-  // Ensure all entities are statically cached so that we do not have to load
-  // them individually when getting their labels below.
-  foreach ($entity_ids as $entity_type => $ids) {
-    $entities[$entity_type] = entity_load_multiple($entity_type, $ids);
-  }
-  $comments = entity_load_multiple('comment', $cids);
-
-  // Build a table listing the appropriate comments.
-  $options = array();
-  $destination = drupal_get_destination();
-
-  foreach ($comments as $comment) {
-    // Use the first entity label.
-    $entity = $entities[$comment->entity_type->value][$comment->entity_id->value];
-    $entity_uri = $entity->uri();
-    // Remove the first node title from the node_titles array and attach to
-    // the comment.
-    $body = '';
-    if (!empty($comment->comment_body->value)) {
-      $body = $comment->comment_body->value;
-    }
-    $options[$comment->id()] = array(
-      'title' => array('data' => array('#title' => $comment->subject->value ?: $comment->id())),
-      'subject' => array(
-        'data' => array(
-          '#type' => 'link',
-          '#title' => $comment->subject->value,
-          '#href' => 'comment/' . $comment->id(),
-          '#options' => array('attributes' => array('title' => truncate_utf8($body, 128)), 'fragment' => 'comment-' . $comment->id()),
-        ),
-      ),
-      'author' => array(
-        'data' => array(
-          '#theme' => 'username',
-          '#account' => comment_prepare_author($comment),
-        ),
-      ),
-      'posted_in' => array(
-        'data' => array(
-          '#type' => 'link',
-          '#title' => $entity->label(),
-          '#href' => $entity_uri['path'],
-          '#options' => $entity_uri['options'],
-          '#access' => $entity->access('view'),
-        ),
-      ),
-      'changed' => format_date($comment->changed->value, 'short'),
-    );
-    $links = array();
-    $links['edit'] = array(
-      'title' => t('Edit'),
-      'route_name' => 'comment.edit_page',
-      'route_parameters' => array('comment' => $comment->id()),
-      'query' => $destination,
-    );
-    if (module_invoke('content_translation', 'translate_access', $comment)) {
-      $links['translate'] = array(
-        'title' => t('Translate'),
-        'route_name' => 'content_translation.translation_overview_comment',
-        'route_parameters' => array('comment' => $comment->id()),
-        'query' => $destination,
-      );
-    }
-    $options[$comment->id()]['operations']['data'] = array(
-      '#type' => 'operations',
-      '#links' => $links,
-    );
-  }
-
-  $form['comments'] = array(
-    '#type' => 'tableselect',
-    '#header' => $header,
-    '#options' => $options,
-    '#empty' => t('No comments available.'),
-  );
-
-  $form['pager'] = array('#theme' => 'pager');
-
-  return $form;
-}
-
-/**
- * Form validation handler for comment_admin_overview().
- *
- * @see comment_admin_overview_submit()
- */
-function comment_admin_overview_validate($form, &$form_state) {
-  $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
-  // We can't execute any 'Update options' if no comments were selected.
-  if (count($form_state['values']['comments']) == 0) {
-    form_set_error('', $form_state, t('Select one or more comments to perform the update on.'));
-  }
-}
-
-/**
- * Form submission handler for comment_admin_overview().
- *
- * Executes the chosen 'Update option' on the selected comments, such as
- * publishing, unpublishing or deleting.
- *
- * @see comment_admin_overview_validate()
- */
-function comment_admin_overview_submit($form, &$form_state) {
-  $operation = $form_state['values']['operation'];
-  $cids = $form_state['values']['comments'];
-
-  if ($operation == 'delete') {
-    entity_delete_multiple('comment', $cids);
-  }
-  else {
-    foreach ($cids as $value) {
-      $comment = comment_load($value);
-
-      if ($operation == 'unpublish') {
-        $comment->status->value = CommentInterface::NOT_PUBLISHED;
-      }
-      elseif ($operation == 'publish') {
-        $comment->status->value = CommentInterface::PUBLISHED;
-      }
-      $comment->save();
-    }
-  }
-  drupal_set_message(t('The update has been performed.'));
-  $form_state['redirect_route']['route_name'] = 'comment.admin';
-  cache_invalidate_tags(array('content' => TRUE));
-}
diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml
index dcb3baa3a180..6273eb7669f3 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'
-    _content: '\Drupal\comment\Controller\CommentController::adminPage'
+    _content: '\Drupal\comment\Controller\AdminController::adminPage'
     type: 'new'
   requirements:
     _permission: 'administer comments'
@@ -11,7 +11,7 @@ comment.admin_approval:
   path: '/admin/content/comment/approval'
   defaults:
     _title: 'Unapproved comments'
-    _content: '\Drupal\comment\Controller\CommentController::adminPage'
+    _content: '\Drupal\comment\Controller\AdminController::adminPage'
     type: 'approval'
   requirements:
     _permission: 'administer comments'
diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php
index 22963bd7e1eb..73785853955e 100644
--- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php
+++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php
@@ -7,11 +7,13 @@
 
 namespace Drupal\comment\Controller;
 
+use Drupal\comment\CommentManagerInterface;
+use Drupal\field\FieldInfo;
 use Drupal\Component\Utility\String;
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Drupal\comment\CommentManagerInterface;
-use Drupal\field\FieldInfo;
+use Drupal\Core\Form\FormBuilderInterface;
+use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -33,13 +35,21 @@ class AdminController extends ControllerBase implements ContainerInjectionInterf
    */
   protected $commentManager;
 
+  /**
+   * The form builder.
+   *
+   * @var \Drupal\Core\Form\FormBuilderInterface
+   */
+  protected $formBuilder;
+
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
     return new static(
       $container->get('field.info'),
-      $container->get('comment.manager')
+      $container->get('comment.manager'),
+      $container->get('form_builder')
     );
   }
 
@@ -50,10 +60,13 @@ public static function create(ContainerInterface $container) {
    *   The field info service.
    * @param \Drupal\comment\CommentManagerInterface $comment_manager
    *   The comment manager service.
+   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
+   *   The form builder.
    */
-  public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager) {
+  public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager, FormBuilderInterface $form_builder) {
     $this->fieldInfo = $field_info;
     $this->commentManager = $comment_manager;
+    $this->formBuilder = $form_builder;
   }
 
   /**
@@ -225,4 +238,25 @@ public function bundleTitle($commented_entity_type, $field_name) {
     return $this->commentManager->getFieldUIPageTitle($commented_entity_type, $field_name);
   }
 
+  /**
+   * 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/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
index b1b127f8bb1a..15f09a71c98c 100644
--- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
+++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
@@ -13,7 +13,6 @@
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Drupal\Core\Session\AccountInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -36,13 +35,6 @@ class CommentController extends ControllerBase implements ContainerInjectionInte
    */
   protected $httpKernel;
 
-  /**
-   * The current user service.
-   *
-   * @var \Drupal\Core\Session\AccountInterface
-   */
-  protected $currentUser;
-
   /**
    * Field info service.
    *
@@ -60,18 +52,15 @@ class CommentController extends ControllerBase implements ContainerInjectionInte
   /**
    * Constructs a CommentController object.
    *
-   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
+   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
    *   HTTP kernel to handle requests.
-   * @param \Drupal\Core\Session\AccountInterface $current_user
-   *   The current user service.
    * @param \Drupal\field\FieldInfo $field_info
    *   Field Info service.
    * @param \Drupal\comment\CommentManagerInterface $comment_manager
    *   The comment manager service.
    */
-  public function __construct(HttpKernelInterface $httpKernel, AccountInterface $current_user, FieldInfo $field_info, CommentManagerInterface $comment_manager) {
-    $this->httpKernel = $httpKernel;
-    $this->currentUser = $current_user;
+  public function __construct(HttpKernelInterface $http_kernel, FieldInfo $field_info, CommentManagerInterface $comment_manager) {
+    $this->httpKernel = $http_kernel;
     $this->fieldInfo = $field_info;
     $this->commentManager = $comment_manager;
   }
@@ -82,7 +71,6 @@ public function __construct(HttpKernelInterface $httpKernel, AccountInterface $c
   public static function create(ContainerInterface $container) {
     return new static(
       $container->get('http_kernel'),
-      $container->get('current_user'),
       $container->get('field.info'),
       $container->get('comment.manager')
     );
@@ -95,6 +83,7 @@ public static function create(ContainerInterface $container) {
    *   A comment entity.
    *
    * @return \Symfony\Component\HttpFoundation\RedirectResponse.
+   *   Redirects to the permalink URL for this comment.
    */
   public function commentApprove(CommentInterface $comment) {
     $comment->status->value = CommentInterface::PUBLISHED;
@@ -178,7 +167,8 @@ public function redirectNode(EntityInterface $node) {
    *   - replies to comments
    *   - replies to entities
    *   - attempts to reply to entities that can no longer accept comments
-   *   - respecting access permissions ('access comments', 'post comments', etc.)
+   *   - respecting access permissions ('access comments', 'post comments',
+   *     etc.)
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
    *   The current request object.
@@ -192,6 +182,7 @@ public function redirectNode(EntityInterface $node) {
    *   (optional) Some comments are replies to other comments. In those cases,
    *   $pid is the parent comment's comment ID. Defaults to NULL.
    *
+   * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
    *   One of the following:
    *   An associative array containing:
@@ -245,7 +236,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
         }
         // Load the parent comment.
         $comment = $this->entityManager()->getStorageController('comment')->load($pid);
-        // Check if the parent comment is published and belongs to the current nid.
+        // Check if the parent comment is published and belongs to the entity.
         if (($comment->status->value == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) {
           drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error');
           return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE)));
@@ -287,11 +278,13 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
    * @param \Symfony\Component\HttpFoundation\Request $request
    *   The request of the page.
    *
+   * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
+   * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    * @return \Symfony\Component\HttpFoundation\JsonResponse
    *   The JSON response.
    */
   public function renderNewCommentsNodeLinks(Request $request) {
-    if ($this->currentUser->isAnonymous()) {
+    if ($this->currentUser()->isAnonymous()) {
       throw new AccessDeniedHttpException();
     }
 
@@ -309,7 +302,7 @@ public function renderNewCommentsNodeLinks(Request $request) {
       $new = comment_num_new($node->id(), 'node');
       $query = comment_new_page_count($node->{$field_name}->comment_count, $new, $node);
       $links[$nid] = array(
-        'new_comment_count' => (int)$new,
+        'new_comment_count' => (int) $new,
         'first_new_comment_link' => $this->urlGenerator()->generateFromPath('node/' . $node->id(), array('query' => $query, 'fragment' => 'new')),
       );
     }
@@ -317,12 +310,4 @@ public function renderNewCommentsNodeLinks(Request $request) {
     return new JsonResponse($links);
   }
 
-  /**
-   * @todo Remove comment_admin().
-   */
-  public function adminPage($type) {
-    module_load_include('admin.inc', 'comment');
-    return comment_admin($type);
-  }
-
 }
diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php
new file mode 100644
index 000000000000..07c6d5486a0c
--- /dev/null
+++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php
@@ -0,0 +1,305 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\comment\Form\CommentAdminOverview.
+ */
+
+namespace Drupal\comment\Form;
+
+use Drupal\comment\CommentInterface;
+use Drupal\comment\CommentStorageControllerInterface;
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Cache\Cache;
+use Drupal\Core\Datetime\Date;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Form\FormBase;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Provides the comments overview administration form.
+ */
+class CommentAdminOverview extends FormBase {
+
+  /**
+   * The entity storage.
+   *
+   * @var \Drupal\Core\Entity\EntityManager
+   */
+  protected $entityManager;
+
+  /**
+   * The comment storage.
+   *
+   * @var \Drupal\comment\CommentStorageControllerInterface
+   */
+  protected $commentStorage;
+
+  /**
+   * The entity query service.
+   *
+   * @var \Drupal\Core\Entity\Query\QueryFactory
+   */
+  protected $entityQuery;
+
+  /**
+   * Date service object.
+   *
+   * @var \Drupal\Core\Datetime\Date
+   */
+  protected $date;
+
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * Creates a CommentAdminOverview form.
+   *
+   * @param \Drupal\Core\Entity\EntityManager $entity_manager
+   *   The entity manager service.
+   * @param \Drupal\comment\CommentStorageControllerInterface $comment_storage
+   *   The comment storage.
+   * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
+   *   The entity query service.
+   * @param \Drupal\Core\Datetime\Date $date
+   *   The date service.
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
+   */
+  public function __construct(EntityManager $entity_manager, CommentStorageControllerInterface $comment_storage, QueryFactory $entity_query, Date $date, ModuleHandlerInterface $module_handler) {
+    $this->entityManager = $entity_manager;
+    $this->commentStorage = $comment_storage;
+    $this->entityQuery = $entity_query;
+    $this->date = $date;
+    $this->moduleHandler = $module_handler;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('entity.manager'),
+      $container->get('entity.manager')->getStorageController('comment'),
+      $container->get('entity.query'),
+      $container->get('date'),
+      $container->get('module_handler')
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormID() {
+    return 'comment_admin_overview';
+  }
+
+  /**
+   * Form constructor for the comment overview administration form.
+   *
+   * @param array $form
+   *   An associative array containing the structure of the form.
+   * @param array $form_state
+   *   An associative array containing the current state of the form.
+   * @param string $type
+   *   The type of the overview form ('approval' or 'new').
+   *
+   * @return array
+   *   The form structure.
+   */
+  public function buildForm(array $form, array &$form_state, $type = 'new') {
+
+    // Build an 'Update options' form.
+    $form['options'] = array(
+      '#type' => 'details',
+      '#title' => $this->t('Update options'),
+      '#attributes' => array('class' => array('container-inline')),
+    );
+
+    if ($type == 'approval') {
+      $options['publish'] = $this->t('Publish the selected comments');
+    }
+    else {
+      $options['unpublish'] = $this->t('Unpublish the selected comments');
+    }
+    $options['delete'] = $this->t('Delete the selected comments');
+
+    $form['options']['operation'] = array(
+      '#type' => 'select',
+      '#title' => $this->t('Action'),
+      '#title_display' => 'invisible',
+      '#options' => $options,
+      '#default_value' => 'publish',
+    );
+    $form['options']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => $this->t('Update'),
+    );
+
+    // Load the comments that need to be displayed.
+    $status = ($type == 'approval') ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED;
+    $header = array(
+      'subject' => array(
+        'data' => $this->t('Subject'),
+        'specifier' => 'subject',
+      ),
+      'author' => array(
+        'data' => $this->t('Author'),
+        'specifier' => 'name',
+        'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
+      ),
+      'posted_in' => array(
+        'data' => $this->t('Posted in'),
+        'class' => array(RESPONSIVE_PRIORITY_LOW),
+      ),
+      'changed' => array(
+        'data' => $this->t('Updated'),
+        'specifier' => 'changed',
+        'sort' => 'desc',
+        'class' => array(RESPONSIVE_PRIORITY_LOW),
+      ),
+      'operations' => $this->t('Operations'),
+    );
+    $cids = $this->entityQuery->get('comment')
+     ->condition('status', $status)
+     ->tableSort($header)
+     ->pager(50)
+     ->execute();
+
+    $comments = $this->commentStorage->loadMultiple($cids);
+
+    // Build a table listing the appropriate comments.
+    $options = array();
+    $destination = drupal_get_destination();
+
+    $commented_entity_ids = array();
+    $commented_entities = array();
+
+    foreach ($comments as $comment) {
+      $commented_entity_ids[$comment->entity_type->value][] = $comment->entity_id->value;
+    }
+
+    foreach ($commented_entity_ids as $entity_type => $ids) {
+      $commented_entities[$entity_type] = $this->entityManager->getStorageController($entity_type)->loadMultiple($ids);
+    }
+
+    foreach ($comments as $comment) {
+      $commented_entity = $commented_entities[$comment->entity_type->value][$comment->entity_id->value];
+      $commented_entity_uri = $commented_entity->uri();
+      $username = array(
+        '#theme' => 'username',
+        '#account' => comment_prepare_author($comment),
+      );
+      $body = '';
+      if (!empty($comment->comment_body->value)) {
+        $body = $comment->comment_body->value;
+      }
+      $comment_permalink = $comment->permalink();
+      $options[$comment->id()] = array(
+        'title' => array('data' => array('#title' => $comment->subject->value ?: $comment->id())),
+        'subject' => array(
+          'data' => array(
+            '#type' => 'link',
+            '#title' => $comment->subject->value,
+            '#href' => $comment_permalink['path'],
+            '#options' => $comment_permalink['options'] + array(
+              'attributes' => array(
+                'title' => Unicode::truncate($body, 128),
+              ),
+            ),
+          ),
+        ),
+        'author' => drupal_render($username),
+        'posted_in' => array(
+          'data' => array(
+            '#type' => 'link',
+            '#title' => $commented_entity->label(),
+            '#href' => $commented_entity_uri['path'],
+            '#options' => $commented_entity_uri['options'],
+            '#access' => $commented_entity->access('view'),
+          ),
+        ),
+        'changed' => $this->date->format($comment->changed->value, 'short'),
+      );
+      $comment_uri = $comment->uri();
+      $links = array();
+      $links['edit'] = array(
+        'title' => $this->t('edit'),
+        'route_name' => 'comment.edit_page',
+        'route_parameters' => array('comment' => $comment->id()),
+        'options' => $comment_uri['options'],
+        'query' => $destination,
+      );
+      if ($this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))) {
+        $links['translate'] = array(
+          'title' => $this->t('translate'),
+          'route_name' => 'content_translation.translation_overview_comment',
+          'route_parameters' => array('comment' => $comment->id()),
+          'options' => $comment_uri['options'],
+          'query' => $destination,
+        );
+      }
+      $options[$comment->id()]['operations']['data'] = array(
+        '#type' => 'operations',
+        '#links' => $links,
+      );
+    }
+
+    $form['comments'] = array(
+      '#type' => 'tableselect',
+      '#header' => $header,
+      '#options' => $options,
+      '#empty' => $this->t('No comments available.'),
+    );
+
+    $form['pager'] = array('#theme' => 'pager');
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, array &$form_state) {
+    $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
+    // We can't execute any 'Update options' if no comments were selected.
+    if (count($form_state['values']['comments']) == 0) {
+      $this->setFormError('', $form_state, $this->t('Select one or more comments to perform the update on.'));
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, array &$form_state) {
+    $operation = $form_state['values']['operation'];
+    $cids = $form_state['values']['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->status->value = CommentInterface::NOT_PUBLISHED;
+        $comment->save();
+      }
+      elseif ($operation == 'publish') {
+        $comment = $this->commentStorage->load($cid);
+        $comment->status->value = CommentInterface::PUBLISHED;
+        $comment->save();
+      }
+    }
+    drupal_set_message($this->t('The update has been performed.'));
+    $form_state['redirect_route'] = array(
+      'route_name' => 'comment.admin',
+    );
+    Cache::invalidateTags(array('content' => TRUE));
+  }
+
+}
diff --git a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php
index 19672775672a..b791b30ae9cc 100644
--- a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php
+++ b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\comment\Form\DeleteConfirmMultiple.
+ * Contains \Drupal\comment\Form\ConfirmDeleteMultiple.
  */
 
 namespace Drupal\comment\Form;
@@ -70,6 +70,9 @@ public function getQuestion() {
    * {@inheritdoc}
    */
   public function getCancelRoute() {
+    return array(
+      'route_name' => 'comment.admin',
+    );
   }
 
   /**
@@ -110,11 +113,7 @@ public function buildForm(array $form, array &$form_state) {
       $form_state['redirect_route']['route_name'] = 'comment.admin';
     }
 
-    $form = parent::buildForm($form, $form_state);
-
-    // @todo Convert to getCancelRoute() after http://drupal.org/node/1986606.
-    $form['actions']['cancel']['#href'] = 'admin/content/comment';
-    return $form;
+    return parent::buildForm($form, $form_state);
   }
 
   /**
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php
index a44b5c9f85b9..e631da2d599d 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php
@@ -93,6 +93,12 @@ function testApprovalAdminInterface() {
     $this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.');
     $this->drupalPostForm(NULL, $edit, t('Delete comments'));
     $this->assertText(t('No comments available.'), 'All comments were deleted.');
+    // Test message when no comments selected.
+    $edit = array(
+      'operation' => 'delete',
+    );
+    $this->drupalPostForm(NULL, $edit, t('Update'));
+    $this->assertText(t('Select one or more comments to perform the update on.'));
   }
 
   /**
-- 
GitLab