diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php index 101c0ec..b6f5ab8 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -159,7 +159,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { ), 'changed' => array( 'data' => $this->t('Updated'), - 'field' => 'c.changed', + 'field' => 'changed', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW), ), @@ -169,31 +169,27 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { $query = $this->connection->select('comment', 'c') ->extend('\Drupal\Core\Database\Query\PagerSelectExtender') ->extend('\Drupal\Core\Database\Query\TableSortExtender'); - if ($this->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'"); - } $result = $query - ->fields('c', array('cid', 'subject', 'name', 'changed', 'entity_id', 'entity_type', 'field_id')) + ->fields('c', array('cid', 'entity_id', 'entity_type')) ->condition('c.status', $status) ->limit(50) ->orderByHeader($header) ->execute(); $cids = array(); - $entity_ids = array(); - $entities = array(); + $commented_entity_ids = array(); + $commented_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; + $commented_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] = $this->entityManager->getStorageController($entity_type)->loadMultiple($ids); + foreach ($commented_entity_ids as $commented_entity_type => $ids) { + $commented_entities[$commented_entity_type] = $this->entityManager->getStorageController($commented_entity_type)->loadMultiple($ids); } $comments = $this->commentStorage->loadMultiple($cids); @@ -202,11 +198,8 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { $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. + $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), @@ -215,18 +208,18 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { if (!empty($comment->comment_body->value)) { $body = $comment->comment_body->value; } + $comment_uri = comment_uri($comment); $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( + '#href' => $comment_uri['path'], + '#options' => $comment_uri['options'] + array( 'attributes' => array( 'title' => Unicode::truncate($body, 128), ), - 'fragment' => 'comment-' . $comment->id(), ), ), ), @@ -234,10 +227,10 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { 'posted_in' => array( 'data' => array( '#type' => 'link', - '#title' => $entity->label(), - '#href' => $entity_uri['path'], - '#options' => $entity_uri['options'], - '#access' => $entity->access('view'), + '#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'), @@ -245,13 +238,15 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { $links = array(); $links['edit'] = array( 'title' => $this->t('edit'), - 'href' => 'comment/' . $comment->id() . '/edit', + 'href' => $comment_uri['path'] . '/edit', + 'options' => $comment_uri['options'], 'query' => $destination, ); if ($this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))) { $links['translate'] = array( 'title' => $this->t('translate'), - 'href' => 'comment/' . $comment->id() . '/translations', + 'href' => $comment_uri['path'] . '/translations', + 'options' => $comment_uri['options'], 'query' => $destination, ); } @@ -301,11 +296,12 @@ public function submitForm(array &$form, array &$form_state) { if ($operation == 'unpublish') { $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->save(); } elseif ($operation == 'publish') { $comment->status->value = COMMENT_PUBLISHED; + $comment->save(); } - $comment->save(); } } drupal_set_message($this->t('The update has been performed.'));