(
So yeah. I wandered into here via DDD Szeged sprinting, drupal8multilingual.org focus issues, which has #2068325: [META] Convert entity SQL queries to the Entity Query API.
I took #2068331: Convert comment SQL queries to the Entity Query API , but until yesterday I hadn't really seen that that one coincides with child issues of #2096923: [meta] Clean-up CommentManager service and deprecate procedural helper functions.
)

I'm trying to split #2068331 out into more manageable chunks. This chunk covers CommentManager as well as CommentStorage... Maybe...

Questions:

  • Do we want to deprecate comment_get_display_page() and comment_get_display_ordinal() too?

comment_get_display_page() has 2 callers (CommentForm::save() & CommentController::permaLink())

comment_get_display_ordinal() only gets called by comment_get_display_page(). Thing is, it must be in CommentStorage.

/**
 * Gets the display ordinal for a comment, starting from 0. [...]
 */
function comment_get_display_ordinal($cid, $instance) {

  [[ SQL gunk that belongs in CommentStorage ]]

  return $query->execute()->fetchField();
}

/**
 * Returns the page number for a comment. [...]
 */
function comment_get_display_page($cid, $instance) {
  $ordinal = comment_get_display_ordinal($cid, $instance);
  $comments_per_page = $instance->getSetting('per_page');
  return floor($ordinal / $comments_per_page);
}
  • If comment_get_display_ordinal() moves to CommentStorage, what do we do with comment_get_display_page()?
    • Stick it in CommentManager?
    • Delete it altogether and make getDisplayOrdinal have a third argument called 'int $divisor'? That could default to 1. If you pass it the number-of-comments-per-page, you get the output of what is now comment_get_display_page()...
  • Do we want to pass the new methods a Comment object instead of a $cid, as the first argument?

My first stab at this, split off from #2068331, kept $cid intact because comment_get_display_page() wants to give it a $cid. But merging comment_get_display_page() into comment_get_display_ordinal() could make it easier to replace the argument with a Comment object...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

roderik’s picture

Status: Active » Needs review

.

roderik’s picture

Issue summary: View changes
larowlan’s picture

+1 to merging

roderik’s picture

FileSize
8.85 KB
8.29 KB

Cool.

Updated patch.
(I didn't heed the 80 column boundary where surrounding code didn't.
Plus added a random coment change because I was just disciplined on https://drupal.org/node/1354#order.)

slashrsm’s picture

Assigned: roderik » slashrsm
slashrsm’s picture

FileSize
8.88 KB

Reroll.

slashrsm’s picture

FileSize
8.47 KB
616 bytes

Merge garbage removed.

marcingy’s picture

Status: Needs review » Needs work
+  $comment = \Drupal::entityManager()->getStorage('comment')->load($cid);
+  return $comment ?
+    \Drupal::entityManager()->getStorage('comment')
+      ->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'))
+    : 0;

Why not

$comment_manager = \Drupal::entityManager()->getStorage('comment');
$comment = $comment_manager->load($cid);
....

Just means the return can be tidied up.

Similar in comment_get_display_page.

if (!user_access('administer comments')) {
+      $query->condition('c1.status', CommentInterface::PUBLISHED);
+    }

This maybe scope creep but user_access is deprecated and we should be using the user service. (\Drupal\Core\Session\AccountInterface::hasPermission().)

+    if ($comment_mode == COMMENT_MODE_FLAT) {

Should COMMENT_MODE_FLAT become a defines for the interface?

slashrsm’s picture

Status: Needs work » Needs review
FileSize
18.73 KB
24.17 KB

Here we go.

Status: Needs review » Needs work

The last submitted patch, 9: 2262407_9.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
24.44 KB
511 bytes

Meh!

Primsi’s picture

Status: Needs review » Needs work
+++ b/core/modules/comment/src/CommentStorage.php
@@ -119,6 +131,38 @@ public function getMaxThreadPerThread(EntityInterface $comment) {
+    // Count how many comments (c1) are before $comment (c2) in display order. This

Comment longer than 80 chars. Apart from that looks ok to me.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
24.44 KB
938 bytes

Fixed and re-rolled.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

marcingy’s picture

13: 2262407_13.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 2262407_13.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
24.42 KB

Reroll.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This needs a change notice to announce the deprecation and the moving of the constants.

diff --git a/core/modules/comment/src/Tests/CommentNodeAccessTest.php b/core/modules/comment/src/Tests/CommentNodeAccessTest.php
index 7e4525c..9882371 100644
--- a/core/modules/comment/src/Tests/CommentNodeAccessTest.php
+++ b/core/modules/comment/src/Tests/CommentNodeAccessTest.php
@@ -8,7 +8,6 @@
 namespace Drupal\comment\Tests;
 
 use Drupal\comment\CommentManagerInterface;
-use Drupal\comment\Entity\Comment;
 use Drupal\simpletest\WebTestBase;
 
 /**
diff --git a/core/modules/comment/src/Tests/CommentPagerTest.php b/core/modules/comment/src/Tests/CommentPagerTest.php
index 295c5e7..a880a2b 100644
--- a/core/modules/comment/src/Tests/CommentPagerTest.php
+++ b/core/modules/comment/src/Tests/CommentPagerTest.php
@@ -6,6 +6,7 @@
  */
 
 namespace Drupal\comment\Tests;
+
 use Drupal\comment\CommentManagerInterface;
 
 /**
diff --git a/core/modules/comment/src/Tests/CommentStatisticsTest.php b/core/modules/comment/src/Tests/CommentStatisticsTest.php
index 7172298..8a9f321 100644
--- a/core/modules/comment/src/Tests/CommentStatisticsTest.php
+++ b/core/modules/comment/src/Tests/CommentStatisticsTest.php
@@ -6,8 +6,8 @@
  */
 
 namespace Drupal\comment\Tests;
+
 use Drupal\comment\CommentManagerInterface;
-use Drupal\comment\Entity\Comment;
 
 /**
  * Tests the comment module administrative and end-user-facing interfaces.

Unnecessary use statements and incorrect spacing.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
24.04 KB
2 KB

Reroll and fixed.

slashrsm’s picture

roderik’s picture

Status: Needs review » Reviewed & tested by the community

@ #19/alexpott: Change record for moving of constants is at https://www.drupal.org/node/2295487

(This was made for #2281475-37: Deprecate comment_new_page_count() and move it functionality into Comment storage controller. Either #228147 or this issue will need a reroll when the other gets committed. I know this isn't ideal but it's better than splitting the constants move out to a separate issue at this point in time...)

--

Many functions in comment.module have been marked @deprecated but are not 'record'ed yet. I think it makes sense (to the reader) to have all these in one change record. (Also all of the issues have seen RTBC already, so I believe the downside for committers to have these in one change record is minimal.)
So I'll go edit slashrsm's change record to add those, and you can tell me to revert/split the text if it must be so.

Meanwhile, this is back to RTBC. (I believe the last interdiff.)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs change record

@roderik yep I agree that once change record for all the removed functions in comment.module is preferable. But each issue needs to be added to this change record - so there is no downside for committers - we just need to see the change record referenced.

Committed 47d6bc0 and pushed to 8.x. Thanks!

diff --git a/core/modules/comment/src/CommentStorageInterface.php b/core/modules/comment/src/CommentStorageInterface.php
index dc6e419..c1e0e72 100644
--- a/core/modules/comment/src/CommentStorageInterface.php
+++ b/core/modules/comment/src/CommentStorageInterface.php
@@ -44,7 +44,8 @@ public function getMaxThreadPerThread(EntityInterface $comment);
    * @param \Drupal\comment\CommentInterface $comment
    *   The comment to use as a reference point.
    * @param int $comment_mode
-   *   Comment mode (COMMENT_MODE_FLAT or COMMENT_MODE_THREADED).
+   *   Comment mode (CommentManagerInterface::COMMENT_MODE_FLAT or
+   *   CommentManagerInterface::COMMENT_MODE_THREADED).
    * @param int $divisor
    *   Defaults to 1, which returns the display ordinal for a comment. If the
    *   number of comments per page is provided, the returned value will be the

Fixed this on commit - the constants COMMENT_MODE_FLAT and COMMENT_MODE_THREADED no longer exist.

  • alexpott committed 47d6bc0 on 8.x
    Issue #2262407 by slashrsm, roderik: Deprecate comment_get_display_page/...
andypost’s picture

+++ b/core/modules/comment/comment.module
@@ -1012,35 +1003,16 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam
+  $comment_storage = \Drupal::entityManager()->getStorage('comment');
...
+  $comment = \Drupal::entityManager()->getStorage('comment')->load($cid);
+  return $comment ? $comment_storage->getDisplayOrdinal($comment, $default_mode) : 0;

needs follow-up to use $comment_storage consistently

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.