Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc’s picture

Status: Active » Needs review
FileSize
34.89 KB

This approach moves these variables to CommentInterface and replaces the occurrences of those variables.

Regards.

Status: Needs review » Needs work

The last submitted patch, 1: move_comment_const-2169361-1.patch, failed testing.

andypost’s picture

Assigned: Unassigned » larowlan

@plopesc Great patch, not so huge as I think!

The trouble here that this constants does not related to comment entity itself, they are used only by comment field as values but we have no CommentFieldInterface and probably moving them into CommentManagerInterface makes more sense.

Let's get @larowlan feedback on it

larowlan’s picture

Inline with #2169447: DX: Supply CacheBackendInterface::CACHE_PERMANENT as Cache::PERMANENT why not CommentItem::OPEN? Provides the best dx?
CommentInterface is the comment entity where as these constants are to do with the field

andypost’s picture

Probably we need to add CommentItemInterface

plopesc’s picture

Status: Needs work » Needs review
FileSize
38.44 KB

New round including new CommentItemInterface. Not sure about if it is placed in the right place...

Interdiff is not included because this patch differs a lot from the previous one.

Regards.

andypost’s picture

I'm fine with this place for interface, RTBC if green.

PS: Will require re-roll If related #2097123: Deprecate comment_num_new() in favour of method on CommentManager commited first

plopesc’s picture

Re-rolling here.

Although #2097123: Deprecate comment_num_new() in favour of method on CommentManager has been postponed, I believe we can continue with this patch.

Regards.

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 8: move_comment_const-2169361-8.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
FileSize
39.21 KB

Re-rolling

plopesc’s picture

Re-rolling

plopesc’s picture

FileSize
39.5 KB

Re-rolling

andypost’s picture

Status: Needs review » Reviewed & tested by the community

RTBC but this one needs change notice draft now

plopesc’s picture

alexpott’s picture

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

move_comment_const-2169361-13.patch no longer applies.

error: patch failed: core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php:58
error: core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php: patch does not apply

plopesc’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
39.51 KB

Re-rolling

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
class CommentItem extends ConfigFieldItemBase {

Shouldn't this now be

class CommentItem extends CommentItemInterface {

And perhaps we should consider adding isOpen(), isHidden(), isClosed() methods?

So then we could do

if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->isOpen())) {>/code>
Instead of
<code>if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) {>/code>

<code>
+++ b/core/modules/forum/forum.install
@@ -5,6 +5,7 @@
+use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;

@@ -83,7 +84,7 @@ function forum_install() {
-    Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'comment_forum', COMMENT_OPEN);
+    Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'comment_forum', CommentItemInterface::OPEN);

We can remove the use and the CommentItemInterface::OPEN as this is the default value.

andypost’s picture

It should be
class CommentItem extends ConfigFieldItemBase implements CommentItemInterface {

+1 to add is* methods

plopesc’s picture

Hello

I'm adding those methods to CommentItem and ComentItemInterface. However, most of times, the comment status comparison is done against the ConfigFieldItemList class, like in the example, and these methods are not available at ItemList level.

We could create new FieldItemList class for comments, called CommentFieldItemList and its interface CommentFieldItemListInterface where we could add those methods in order to be able to do $entity->{$field_name}->isOpen();

What do you think?

andypost’s picture

Discussed with @berdir

<berdir> andypost: yes,you can't do that directly
<berdir> andypost: not sure if it's worth it to add a list class just for that
<berdir> it's also something any other field type does atm
<andypost> plopesc, ^^
<andypost> berdir, and you think it's fine to $entity->comment->isOpen();
<berdir> andypost: I'd suggest to open a follow-up issue to look into it, also possibly for other field types
<berdir> andypost: maybe we could consider a __call()  method on the list, that forwards to items, but not sure about adding more magic
andypost’s picture

I think we should file a follow-up anyway, because comment field has more than "value" inside.
Let's just fix #19 in issue scope and file new issue to discuss methods and integration of {comment_entity_statistics} from
#148849: Refactor {comment_entity_statistics} into performant Field and #2101183: Move {comment_entity_statistics} to proper service

Berdir’s picture

Yes, adding methods on field item classes is not something anyone else is doing and has the mentioned issues, adding a class and interface to repeat it on the level would be pretty unfortunate.

plopesc’s picture

Status: Needs work » Needs review
FileSize
39.74 KB
1.35 KB

New patch fixing class declaration and removing unnecessary reference in forum.install.

plopesc’s picture

plopesc’s picture

FileSize
39.73 KB

Re-rolling previous patch no longer applies.

plopesc’s picture

FileSize
39.77 KB

Re-rolling. Previous patch no longer applies...

andypost’s picture

andypost’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc

alexpott’s picture

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

We need a change record for this before we can commit - once one exists can set back to rtbc

plopesc’s picture

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

There is already a change record for this issue COMMENT_HIDDEN & COMMENT_CLOSED & COMMENT_OPEN converted to constants on CommentItemInterface.

Setting back to RTBC.

YesCT’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Missed it - sorry.

Committed fd2613d and pushed to 8.x. Thanks!

plopesc’s picture

@alexpott no problem. Thank you so much :)

Status: Fixed » Closed (fixed)

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