Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.

See the detailed explanations there and look at the issues that already have patches or were committed.

Add get*, set* and additional methods as it makes sense to replace the public properties (e.g. isSomething() and something())

---------------------
Please read the meta linked above. Put other information specific to this issue here, especially if there is anything complicated or different from the other sub-tasks of that meta.
---------------------

The focus of this issue is to add methods for base fields. See Entity/Comment::baseFieldDefinitions().
Adding methods for other properties will be saner to do after this is separate issues.

Not to be done in this issue, and done in other issues:

Not to be converted at all:

  • ->comment_body See @Berdir in #28 Why? Because body is a configurable field.
  • ->changed->value to setChangedTime() See @Berdir in #28. Why? Because: It's only set internally. We dont want a public way to set it.
  • ->seen in CommentLinksTest Why? It's only used in that one test, only ever set. Can be a separate issue to take it out.
  • ->last_comment_name ->last_comment_uid ->comment_count ->cid ->last_comment_timestamp Why? Because: these are on node comment fields, not on comments.
  • ->view in views.module Why? Because: is not on a comment object. Is part of an array used for theme alter. (?)

These are not converted here:
because this issue is focused on adding methods for base fields. Might be useful though, as separate issues.

  • ->in_preview
  • ->divs ->divs_final and ->depth Why? Additionally because maybe we shouldn't be doing that anyway. Can be discussed in separate issue.
  • ->link ->rss_namespaces ->rss_elements Why Because in core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php ... those are internal only?
  • ->date in CommentFormController

Not to be refactored:

Other issues for bugs/things noticed:

  • #78 D (a minor should live else where),
  • #78 G (needs test coverage)

Q: Why is the patch so large?
A: The size of this patch increased a bunch after #731724: Convert comment settings into a field to make them work with CMI and non-node entities went in. See #24

Q: What is going on besides a simple conversion?
A: Not much, but there are a lot of properties and a lot of code that accessed them. There is a little bit of standards fixing in near lines, but not enough to needs work it to take them out.

CommentFileSizeAuthor
#97 comment-interface-patch-diff.txt3.96 KBberdir
#97 comment-interface-2028025.97.patch114.17 KBberdir
#94 comment-interface-2028025.94-interdiff.txt5.45 KBberdir
#94 comment-interface-2028025.94.patch114.19 KBberdir
#63 interdiff.txt1013 byteslarowlan
#63 comment-interface-2028025.63.patch102.5 KBlarowlan
#61 comment-interface-2028025.61.patch102.36 KBlarowlan
#58 comment-interface-2028025.58.patch100.41 KBlarowlan
#55 comment-methods-2028025-54-interdiff.txt987 bytesberdir
#55 comment-methods-2028025-54.patch99.84 KBberdir
#43 result.txt0 bytesa_thakur
#87 comment-interface-2028025.87-interdiff.txt3.33 KBberdir
#87 comment-interface-2028025.87.patch114.46 KBberdir
#85 comment-interface-2028025.85-interdiff.txt32.83 KBberdir
#85 comment-interface-2028025.85.patch113.73 KBberdir
#83 interdiff-80-83.txt738 bytesyesct
#83 comment-interface-2028025.83.patch100.69 KByesct
#80 comment-interface-2028025.80.patch101.03 KBberdir
#74 comment-interface-2028025.74.patch102.88 KByesct
#74 interdiff-2028025-66-74.txt5.09 KByesct
#66 comment-interface-2028025.67.patch102.93 KBlarowlan
#65 comment-interface-2028025.65.patch102.5 KBlarowlan
#65 interdiff.txt719 byteslarowlan
#61 interdiff.txt2.42 KBlarowlan
#53 comment-methods-2028025-52-interdiff.txt1.08 KBberdir
#53 comment-methods-2028025-52.patch99.85 KBberdir
#50 comment-methods-2028025-50-interdiff.txt1.26 KBberdir
#50 comment-methods-2028025-50.patch99.94 KBberdir
#48 comment-methods-2028025-48.patch100.28 KBberdir
#42 drupal8.comment-module.2028025-42.patch102.06 KBjohnennew
#38 drupal8.comment-module.2028025-38.patch103.71 KBjohnennew
#38 interdiff-2028025-35-38.txt10.2 KBjohnennew
#35 drupal8.comment-module.2028025-35.patch95.95 KBjohnennew
#35 interdiff-2028025-26-35.txt41.86 KBjohnennew
#26 drupal8.comment-module.2028025-26.patch94.41 KBjohnennew
#18 expand-comment-interface-2028025-18.patch20.78 KBDavid Hernández
#18 interdiff.txt3.21 KBDavid Hernández
#16 expand-comment-interface-2028025-16.patch18.34 KBDavid Hernández
#16 interdiff.txt1.14 KBDavid Hernández
#15 expand-comment-interface-2028025-15.patch18.02 KBDavid Hernández
#15 interdiff.txt787 bytesDavid Hernández
#12 expand-comment-interface-2028025-12.patch18.01 KBDavid Hernández
#12 interdiff.txt946 bytesDavid Hernández
#10 expand-comment-interface-2028025-8.patch18 KBDavid Hernández
#10 interdiff.txt2.08 KBDavid Hernández
#9 expand-comment-interface-2028025-8.patch18 KBDavid Hernández
#9 interdiff.txt2.08 KBDavid Hernández
#8 interdiff.txt2.08 KBDavid Hernández
#6 expand-comment-interface-2028025-6.patch17.96 KBDavid Hernández
#6 interdiff.txt13.09 KBDavid Hernández
#4 expand-command-interface-2028025-4.patch16.86 KBDavid Hernández
#4 interdiff.txt2.87 KBDavid Hernández
#2 expand-command-interface-2028025-2.patch16.56 KBDavid Hernández

Comments

David Hernández’s picture

Assigned: Unassigned » David Hernández

Working on this.

David Hernández’s picture

Status: Active » Needs review
StatusFileSize
new16.56 KB

Here is a first version of the patch, only refactoring the CommentInterface and the Comment class implementing it.

Status: Needs review » Needs work

The last submitted patch, expand-command-interface-2028025-2.patch, failed testing.

David Hernández’s picture

Status: Needs work » Needs review
StatusFileSize
new2.87 KB
new16.86 KB

PHP syntax issues should be fixed now.

berdir’s picture

Status: Needs review » Needs work

Looks good, feedback below, mostly on documentation and naming.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * The parent comment entity if this is a reply to a comment.
+   *
+   * @return int

Should start with verb in third tense, for getters usually Returns.

@return type for this is \Drupal\comment\CommentInterface|null.

All @return's need a description even if it's very similar to the method description.

For example in this case, I would suggest to keep the method description very short, e.g. "Returns the parent comment entity."

And the @return description can extend it additional with an " or NULL if there is no parent".

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * @todo: Rename to 'parent_id'.

No need for the @todo here (it's already called parentId so the todo is weird).

Instead, let's move the @todo to CommentStorageController::baseFieldDefinitions(), where pid is defined.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * @return \Drupal\Core\Entity\EntityInterface

Here the type is \Drupal\node\NodeInterface.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+
+  /**
+   * The comment language code.
+   *
+   * @return string
+   */
+  public function getLangcode();

We have the generic language() method, I think we don't need to duplicate that.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * @return int

This is a \Drupal\user\UserInterface.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * @return \Drupal\comment\Plugin\Core\Entity\CommentInterface

All interfaces are in the main namespace directory, see above, Drupal\comment\CommentInterface in this case.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+  public function setName($name);

Possibly also name this setAuthorName(), to be consistent with getAuthorName()

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+  public function getHomepage();

Also add a setter for this?

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+  public function getCreated();

We usually use getCreatedTime() and getChangedTime() for these.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+  /**
+   * A boolean field indicating whether the comment is published.
+   *
+   * @return int
+   */
+  public function getChanged();

Description doesn't match.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+  public function setChanged($changed);

Not sure if we want to have a setter for this. We're setting it but only internally in the Comment class. It's not something that can be set really, because it's forcefully overwritten every time the entity is saved.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+   * A boolean field indicating whether the comment is published.
+   *
+   * @return bool
+   */
+  public function isPublished();
...
+   */
+  public function setStatus($status);

I'd go for setPublished(), that's what I did in NodeInterface.

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,217 @@
+
+  /**
+   * The comment node type.
+   *
+   * @return string
+   */
+  public function getNodeType();
+
+  /**
+   * Sets the comment node type.
+   *
+   * @param string $node_type
+   *   The node type where the comment is attached.
+   *
+   * @return \Drupal\comment\Plugin\Core\Entity\CommentInterface
+   *   The class instance that this method is called on.
+   */
+  public function setNodeType($node_type);

this is not actually the node type, it's comment_$node_type, and that is covered by the bundle() method.

Changing the bundle is not something that's really supported, crazy things can then happen and it would essentially mean that we move the comment to not only a different node a but a node of a different type :) So I would leave that out, indicating that it can't be changed.

David Hernández’s picture

Status: Needs work » Needs review
StatusFileSize
new13.09 KB
new17.96 KB

Renamed the patch file to be a correct description.

Fixed issues from #5.

Status: Needs review » Needs work

The last submitted patch, expand-comment-interface-2028025-6.patch, failed testing.

David Hernández’s picture

StatusFileSize
new2.08 KB

Still working on this, just a quick update. There were some inconsistencies on the naming of the getters/setters that are now fixed. This will fix most of the tests, but still lots of things that need to be reviewed.

David Hernández’s picture

StatusFileSize
new2.08 KB
new18 KB

Still working on this, just a quick update. There were some inconsistencies on the naming of the getters/setters that are now fixed. This will fix most of the tests, but still lots of things that need to be reviewed.

David Hernández’s picture

StatusFileSize
new2.08 KB
new18 KB

Still working on this, just a quick update. There were some inconsistencies on the naming of the getters/setters that are now fixed. This will fix most of the tests, but still lots of things that need to be reviewed.

David Hernández’s picture

Sorry for the duplicated comments. drupal.org was acting funny...

David Hernández’s picture

StatusFileSize
new946 bytes
new18.01 KB

I missed a couple functions renaming. That should fix a few more tests, but still no green light.

seantwalsh’s picture

Status: Needs work » Needs review

Changed to needs review so test runs against patch.

Status: Needs review » Needs work

The last submitted patch, expand-comment-interface-2028025-12.patch, failed testing.

David Hernández’s picture

Status: Needs work » Needs review
StatusFileSize
new787 bytes
new18.02 KB

New patch. Still not completly green, but getting close.

David Hernández’s picture

StatusFileSize
new1.14 KB
new18.34 KB

Ok, this might be green.

Status: Needs review » Needs work

The last submitted patch, expand-comment-interface-2028025-16.patch, failed testing.

David Hernández’s picture

Status: Needs work » Needs review
StatusFileSize
new3.21 KB
new20.78 KB

I think that's it.

yesct’s picture

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.phpundefined
@@ -15,6 +15,216 @@
+   * Returns the parent comment entity if this is a reply to a comment.
+   *
+   * @return \Drupal\comment\CommentInterface|null
+   *   A Comment Entity of the parent comment or null if there is no parent.
...
+   * @return \Drupal\comment\CommentInterface|null
+   *   The class instance that this method is called on.
+   */
+  public function setAuthorName($name);

+++ b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.phpundefined
@@ -52,160 +52,192 @@
+  /**
+   * {@inheritdoc}
+   */
+  public function setAuthorName($name) {
+    $this->set('name', $name);
+    return $this;
+  }

Why are setters, like setAuthorName, returning the type or null?

I think sometimes |null makes sense, but when it's return $this, it's just the class?

See @Berdir's comment in #2028037-11: Expand FeedInterface with methods

I see in this issue in #5
it was said to make the return \Drupal\comment\CommentInterface|null but I think that is only in the case where the description was like "if this is a reply to a comment" like for getParent and getParentId. And the null is what is returned if it is not a reply to a comment.

David Hernández’s picture

Assigned: David Hernández » Unassigned

Unassigned

johnennew’s picture

Assigned: Unassigned » johnennew
Status: Needs review » Active

Looking at this now - patch needs a reroll.

berdir’s picture

You might want to only keep the methods on the class and interface for now. There's a critical issue that's completely turning comments upside down and this would conflict quite a bit with that.

johnennew’s picture

Assigned: johnennew » Unassigned

Taking myself off this one - say when the comment patch goes in and I'll come back again if I can.

tim.plunkett’s picture

@ceng, it went in last night!

johnennew’s picture

Assigned: Unassigned » johnennew

Picking this up now.

johnennew’s picture

Status: Active » Needs review
StatusFileSize
new94.41 KB

Hi, new patch ready for review. I can't create an interdiff, probably because its too different now?

  1. Renamed *Node() to *Entity() now comments fields on any entity
  2. Added a getFieldId() and getFieldName() and the setters
  3. Replaced all instances of direct access to the Comment Entity properties with the get or set methods which exist in the comment module including it's tests
  4. Question: There are three reads of a property called $comment->is_anonymous in the D8 codebase but no writes to that property. It is therefore always NULL - can it be removed?
  5. Question: There is code which reads and writes to a property called $comment->comment_body - should this have a get and set method? Maybe one for a follow up issue?
  6. Question: There is code which reads and writes to a property called $comment->is_preview - should this have a get and set method? Maybe one for a follow up issue?
  7. Question: The $comment->getPublished() method can return NULL at present since it returns the value of the $status variable which has a tri-state, it can be COMMENT_PUBLISHED, COMMENT_NOT_PUBISHED or NULL (meaning unknown, this is checked for repeatedly in the code). I think the function should be returning TRUE or FALSE though this will require some rewriting of where it is used. One for a follow up issue?
larowlan’s picture

There are three reads of a property called $comment->is_anonymous in the D8 codebase but no writes to that property. It is therefore always NULL - can it be removed?

Pretty sure there's a #value field in the comment form-controller called is_anonymous, so in this instance its a property from submitted form values.

There is code which reads and writes to a property called $comment->comment_body - should this have a get and set method? Maybe one for a follow up issue?

This is a field, we can switch it to ->get('comment_body') or leave as is

There is code which reads and writes to a property called $comment->is_preview - should this have a get and set method? Maybe one for a follow up issue?

There is no property for this, but its set when the 'preview' button is clicked. We should look at how node does it or add a in_preview property with get/set

The $comment->getPublished() method can return NULL at present since it returns the value of the $status variable which has a tri-state, it can be COMMENT_PUBLISHED, COMMENT_NOT_PUBISHED or NULL (meaning unknown, this is checked for repeatedly in the code). I think the function should be returning TRUE or FALSE though this will require some rewriting of where it is used. One for a follow up issue?

I agree, lets make it TRUE or FALSE only

berdir’s picture

Status: Needs review » Needs work

Pretty sure there's a #value field in the comment form-controller called is_anonymous, so in this instance its a property from submitted form values.

If that's the case, then I doubt that's set. The NG (now ContentEntity) form controller only sets explicitly defined fields, everything else is ignored. You have to override and extend buildEntity() to set more stuff, see NodeFormController.

Yes, comment_body is a configurable field, shouldn't get it's own method.

  1. +++ b/core/modules/comment/comment.admin.inc
    @@ -119,7 +119,7 @@ function comment_admin_overview($form, &$form_state, $arg) {
    -    $entity = $entities[$comment->entity_type->value][$comment->entity_id->value];
    +    $entity = $entities[$comment->getEntityType()][$comment->getEntityId()];
    

    I don't think getEntityType() and ..Id() as method names work. That's extremely close to entityType() but something else.

    Is mentioned before, we need a term for the entity that a comment is attached to and then us that. parent? host?

  2. +++ b/core/modules/comment/comment.module
    @@ -1201,7 +1201,7 @@ function comment_user_cancel($edit, $account, $method) {
    -        $comment->uid->target_id = 0;
    +        $comment->setAuthorId(0);
    

    Note that https://drupal.org/node/2078387 also adds getAuthorId(), getAuthor() and setAuthorId() to comments and does some conversions.

  3. +++ b/core/modules/comment/comment.module
    @@ -1381,27 +1381,29 @@ function comment_get_display_page($cid, $instance) {
    +    $comment->setChangedTime(REQUEST_TIME);
    

    We shouldn't add a setChangedTime() method. There are some cases where it is set, but it's not really a public API.

  4. +++ b/core/modules/comment/comment.module
    @@ -1577,7 +1579,7 @@ function template_preprocess_comment(&$variables) {
    -    $variables['status'] = ($comment->status->value == COMMENT_NOT_PUBLISHED) ? 'unpublished' : 'published';
    +    $variables['status'] = $comment->isPublished() == COMMENT_NOT_PUBLISHED ? 'unpublished' : 'published';
    

    According to this logic, if the status is NULL then it would be published? +1 on isPublished() to return bool btw.

  5. +++ b/core/modules/comment/comment.tokens.inc
    @@ -136,32 +136,32 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    -          $name = ($comment->uid->target_id == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->name->value;
    +          $name = ($comment->getAuthorId() == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->getAuthorName();
               $replacements[$original] = $sanitize ? filter_xss($name) : $name;
    

    I think this kind of logic should be hidden in getAuthorName(), see getUsername() on users. Then we don't have to set somewhere above.

  6. +++ b/core/modules/comment/comment.tokens.inc
    @@ -181,26 +181,27 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
             // Default values for the chained tokens handled below.
             case 'author':
    -          $replacements[$original] = $sanitize ? filter_xss($comment->name->value) : $comment->name->value;
    +          $replacements[$original] = $sanitize ? filter_xss($comment->getAuthorName()) : $comment->getAuthorName();
    

    So we have a name and an author token which is more or less the same?

  7. +++ b/core/modules/comment/comment.tokens.inc
    @@ -181,26 +181,27 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    +          $parent_id = $comment->getParentId();
    +          if (!empty($parent_id)) {
    +            $parent = entity_load('comment', $parent_id);
    

    No need for the !empty() check, if ($parent_id = $comment->getParentId()) is fine. !empty() is a left-over of the stdClass $entity object times.

    We could even add a getParentComment() method?

  8. +++ b/core/modules/comment/comment.tokens.inc
    @@ -209,8 +210,8 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    -          if ($comment->entity_type->value == 'node') {
    -            $entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
    +          if ($comment->getEntityType() == 'node') {
    +            $entity = entity_load($comment->getEntityType(), $comment->getEntityId());
    

    similar for this, not yet sure how to name it, but there should be a method to get the entity.

    get*EntityId()
    get*EntityType()
    get*Entity()

    Depending on *, "Entity" might or might not be necessary.

  9. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -16,6 +16,279 @@
    +  /**
    +   * Returns the entity the comment is attached to.
    +   *
    +   * @return \Drupal\Core\Entity\EntityInterface
    +   *   The entity on which the comment is attached.
    +   */
    +  public function getEntity();
    

    Ah, you do have a method, just not used yet there :)

  10. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -56,156 +56,229 @@
    +  public function getEntity() {
    +    return $this->get('entity_id')->entity;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getEntityId() {
    +    return $this->get('entity_id')->target_id;
    +  }
    

    This, unfortunatly, doesn't work.

    the field definition of entity_id is a lie.

    No idea why it got in like this, but it's wrong. entity_id needs to be simple integer_field and getEntity needs to manually load the entity based on the other two methods.

  11. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -56,156 +56,229 @@
    -  public $cid;
    +  public function getAuthor() {
    +    return $this->get('uid')->entity;
    +  }
    

    Hint: If you add the new methods at the end or near the end of the class, then the diff might be much easier to read as it should first remove all properties and then add the new methods instead of this mix. Try it out.

larowlan’s picture

vote 1 commentedEntity

andypost’s picture

+1 to getCommentedEntity()

tstoeckler’s picture

With threaded comments, comments can sometimes be on other comments yet getCommentedEntity would return e.g. the parent node, right? So not sure getCommentedEntity() works well in that case.

berdir’s picture

getCommentedEntity() works for me, in threads, we have getParentId() and possibly getParentComment().

johnennew’s picture

Status: Needs work » Active

Thanks all for your comments - I'm going to add all these items into this patch then rather than creating any follow up issues.

johnennew’s picture

+++ b/core/modules/comment/comment.module
@@ -1577,7 +1579,7 @@ function template_preprocess_comment(&$variables) {
-    $variables['status'] = ($comment->status->value == COMMENT_NOT_PUBLISHED) ? 'unpublished' : 'published';
+    $variables['status'] = $comment->isPublished() == COMMENT_NOT_PUBLISHED ? 'unpublished' : 'published';
According to this logic, if the status is NULL then it would be published? +1 on isPublished() to return bool btw.

in PHP, this is actually TRUE ... (0 == NULL), so the logic is right, despite reading badly! Will work out the boolean return.

johnennew’s picture

Status: Active » Needs review
StatusFileSize
new41.86 KB
new95.95 KB

1. I don't think getEntityType() and ..Id() as method names work. That's extremely close to entityType() but something else.

I've gone for getCommentedEntity(), getCommentedEntityId() and getCommentedEntityType() as suggested.

2. Note that https://drupal.org/node/2078387 also adds getAuthorId(), getAuthor() and setAuthorId() to comments and does some conversions.

I've left these modifications - will probably have to remove when this patch goes in?

3. We shouldn't add a setChangedTime() method. There are some cases where it is set, but it's not really a public API.

OK, I've removed this and set back to setting the value directly. What about setCreatedTime()?

4. According to this logic, if the status is NULL then it would be published? +1 on isPublished() to return bool btw.

isPublished() returns a bool now - I've updated the places it was used in the code and checked the workflows and all seems well (tests seem to be passing too)

5. I think this kind of logic should be hidden in getAuthorName(), see getUsername() on users. Then we don't have to set somewhere above.

I copied the same process as getUsername() in User Entity as suggested so it happens in the Comment class and and updated the external versions.

6. So we have a name and an author token which is more or less the same?

I've dropped the name token and updated the tests.

7. No need for the !empty() check, if ($parent_id = $comment->getParentId()) is fine. !empty() is a left-over of the stdClass $entity object times. We could even add a getParentComment() method?

I removed getParentId() and added a hasParentComment() method instead since getParentId() was mostly used for determining if there was a parent at all. This makes the code easier to read. To get the parent comment itself there is now a getParentComment() as suggested.

8. similar for this, not yet sure how to name it, but there should be a method to get the entity.

As per 1 above, added getCommentedEntity*() methods.

9. Ah, you do have a method, just not used yet there :)

Made use of the getCommentedEntity() function in the appropriate places.

10. the field definition of entity_id is a lie. No idea why it got in like this, but it's wrong. entity_id needs to be simple integer_field and getEntity needs to manually load the entity based on the other two methods.

entity_id is now an integer field defined in the Comment::baseFieldDefinitions() function. getCommentedEntity() loads the entity as suggested.

11. Hint: If you add the new methods at the end or near the end of the class, then the diff might be much easier to read as it should first remove all properties and then add the new methods instead of this mix. Try it out.

Woah, pro tip FTW!

This leaves the $comment->is_anonymous and $comment->is_preview variables still to tidy up. I think this patch is good to go if these are moved out to follow up issues, the patch is getting quite big with a number of changes. Or I can add to this one if everyone is happy with that.

berdir’s picture

- setCreatedTime() is a valid use case, so that is fine.
- Yes, you can leave the author stuff, one of those two issues will need a re-roll if the other one gets in but that's fine
- Not too sure about removing the token. That's basically an API change and one that is ugly to take care of because we don't know where that token was used. Maybe better to keep and add a @todo that says it's identical to author and should be dropped.

Everything else sounds fine, haven't looked at the patch yet.

-

+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -459,17 +306,234 @@ public static function baseFieldDefinitions($entity_type) {
+   */
   public function getChangedTime() {
-    return $this->changed->value;
+    $changed_time = $this->get('changed');
+    if (!empty($changed_time)) {
+      return $changed_time->value;
+    }
   }

Huh, why is that necessary? get('changed')->value should work fine? (changed->value too, but I prefer get() in those methods).

Status: Needs review » Needs work

The last submitted patch, drupal8.comment-module.2028025-35.patch, failed testing.

johnennew’s picture

Status: Needs work » Needs review
StatusFileSize
new10.2 KB
new103.71 KB

Not too sure about removing the token. That's basically an API change and one that is ugly to take care of because we don't know where that token was used. Maybe better to keep and add a @todo that says it's identical to author and should be dropped.

Put name back in, its the same code as author

Huh, why is that necessary? get('changed')->value should work fine? (changed->value too, but I prefer get() in those methods).

It isn't necessary and I've taken it out.

Test fail because of the hook_comment_* - needed to go through and update all implementations of the hook_comment_* in node, tracker, rdf and forum modules.

andypost’s picture

berdir’s picture

Status: Needs review » Needs work

The last submitted patch, 38: drupal8.comment-module.2028025-38.patch, failed testing.

johnennew’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new102.06 KB

Rerolled patch attached

a_thakur’s picture

StatusFileSize
new0 bytes

Patch in comment #42 did not apply.

a_thakur’s picture

Status: Needs review » Needs work

Changing to Needs work.

a_thakur’s picture

Please ignore this file.

berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 42: drupal8.comment-module.2028025-42.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new100.28 KB

Lots of conflicts.

Status: Needs review » Needs work

The last submitted patch, 48: comment-methods-2028025-48.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new99.94 KB
new1.26 KB

The last submitted patch, 50: comment-methods-2028025-50.patch, failed testing.

The last submitted patch, 50: comment-methods-2028025-50.patch, failed testing.

berdir’s picture

Another merge conflict...

The last submitted patch, 53: comment-methods-2028025-52.patch, failed testing.

berdir’s picture

Copy & paste stupidity

berdir’s picture

The last submitted patch, 55: comment-methods-2028025-54.patch, failed testing.

larowlan’s picture

StatusFileSize
new100.41 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 58: comment-interface-2028025.58.patch, failed testing.

The last submitted patch, 58: comment-interface-2028025.58.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
new102.36 KB

Should fix the threadLock test

Status: Needs review » Needs work

The last submitted patch, 61: comment-interface-2028025.61.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new102.5 KB
new1013 bytes

grumble grumble

The last submitted patch, 63: comment-interface-2028025.63.patch, failed testing.

larowlan’s picture

StatusFileSize
new719 bytes
new102.5 KB

passes locally, but clearly testbot is different kettle

larowlan’s picture

StatusFileSize
new102.93 KB

Re-roll after removal of comment_alphadecimal_to_int() etc went in
I'm happy this is ready

Status: Needs review » Needs work

The last submitted patch, 66: comment-interface-2028025.67.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 66: comment-interface-2028025.67.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
yesct’s picture

  1. +++ b/core/modules/comment/comment.module
    @@ -1084,7 +1084,7 @@ function comment_user_cancel($edit, $account, $method) {
    -        $comment->status->value = 0;
    +        $comment->setPublished(COMMENT_NOT_PUBLISHED);
    

    did I see somewhere else we are not using the constants, but using true and false?

  2. +++ b/core/modules/comment/comment.module
    @@ -1274,26 +1274,28 @@ function comment_get_display_page($cid, $instance) {
    +      $account = user_load_by_name($author_name);
    ...
    -    else {
    -      $comment->name->value = \Drupal::config('user.settings')->get('anonymous');
    +    elseif (empty($author_name)) {
    +      $comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
    

    I looked at this logic change from else to elseif, and got confused by the whole first bit of comment_preview(). It's like it loads based on the name and then sets the name..

    We shouldn't refactor comments to make more sense in this issue, so as long as it is correct, I guess it is fine.

    Here is the logic in context:

    /**
     * Generates a comment preview.
     *
     * @param \Drupal\comment\CommentInterface $comment
     *   The comment entity to preview.
     *
     * @return array
     *   An array as expected by drupal_render().
     */
    function comment_preview(CommentInterface $comment, array &$form_state) {
      $preview_build = array();
      $entity = entity_load($comment->getCommentedEntityType(), $comment->getCommentedEntityId());
    
      if (!form_get_errors($form_state)) {
        // Attach the user and time information.
        $author_name = $comment->getAuthorName();
        if (!empty($author_name)) {
          $account = user_load_by_name($author_name);
        }
        elseif (\Drupal::currentUser()->isAuthenticated() && empty($comment->is_anonymous)) {
          $account = \Drupal::currentUser();
        }
    
        if (!empty($account) && $account->isAuthenticated()) {
          $comment->setAuthorId($account->id());
          $comment->setAuthorName(check_plain($account->getUsername()));
        }
        elseif (empty($author_name)) {
          $comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
        }
    
  3. +++ b/core/modules/comment/comment.tokens.inc
    @@ -136,32 +136,22 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
             case 'mail':
    -          if ($comment->uid->target_id != 0) {
    -            $mail = $comment->uid->entity->getEmail();
    -          }
    -          else {
    -            $mail = $comment->mail->value;
    -          }
    +          $mail = $comment->getAuthorEmail();
    
    +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -454,8 +303,214 @@ public static function baseFieldDefinitions($entity_type) {
    +  public function getAuthorEmail() {
    +    $mail = $this->get('mail')->value;
    +
    +    if ($this->get('uid')->target_id != 0) {
    +      $mail = $this->get('uid')->entity->getEmail();
    +    }
    +
    +    return $mail;
    

    why was the logic rewritten like this instead of the original if/else?

    So code inspection in an IDE does not warn that the return value might not be set? (chx in irc says code inspection is smart enough, so that wasn't the reason)

  4. +++ b/core/modules/comment/comment.tokens.inc
    @@ -136,32 +136,22 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    +          $replacements[$original] = $sanitize ? filter_xss($comment->getSubject()) : $comment->getSubject();
    
    @@ -179,28 +169,30 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    +          $name = $comment->getAuthorName();
    +          $replacements[$original] = $sanitize ? filter_xss($name) : $name;
    

    sometimes getX() is called once, and then the var used. more often in its ... ? filter_xss($c->getX()) : $c->getX(); with two calls to the get. We could later do a follow-up to make it consistent if that would be useful.

  5. +++ b/core/modules/comment/comment.tokens.inc
    @@ -179,28 +169,30 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    -        // Default values for the chained tokens handled below.
    ...
    +        case 'name':
    

    adding issue for this todo. #920056: [comment:name] duplicates [comment:author], and the latter should use format_username()

  6. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -26,6 +26,257 @@
    +   * Returns the ID of the comment field the comment is attached to.
    +   *
    +   * @return int
    +   *   The field ID of the field the comment is attached to.
    +   */
    +  public function getFieldId();
    

    huh. comments get attached to specific comment fields on the entities they are attached to? (larowlan says yes) Can we have more than one comment field on an entity? (larowlan says yes) Do we "enable commenting" by adding a comment field? (answering my own question: add the field, then edit settings on that field to enable commenting.) So. That leads me to think that the getCommentedEntity() returns the entity that field is on. and comments on different fields might be attached to the same entity. Maybe I'll draw myself a picture.

  7. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -26,6 +26,257 @@
    +   * Set the field ID for which this commment is attached.
    +   *
    +   * @param string $field_id
    +   *   The field identifier
    

    a) commment is mis-spelled. I fixed it.

    b) is the field ID a string? My guess is it would be an int, like getFieldId(). But larowlan, via irc, says. it might be getFieldId that the type is wrong on. "FieldId is of the form {entity_type}__{field_name}" I'll leave it as string for now. Maybe we need to change the return type of getFieldId(). Seems Entity/Field has $id which is a string, but a different format. OK. so talked more to larowlan. Idea for followup is: since bundle() might be the same as getFieldId(), getFieldId() might not be needed and we could repurpose it "to map node__comment to node.comment, and make it useful, and a place to document this."

    c) missing period. I added it.

  8. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -222,23 +73,21 @@ public function id() {
    -        if ($this->pid->target_id == 0) {
    +        if (! $this->hasParentComment()) {
               // This is a comment with no parent comment (depth 0): we start
               // by retrieving the maximum thread level.
    

    no parent is no longer determined by checking if (depth) is 0. I almost changed the comment about the if... but

    I read the next bit of code about max depth, but I could not decide if noting something with no parent had a depth of 0 would be useful. I left it.

Not done yet. Posting what I have so far so I dont lose it.

yesct’s picture

Assigned: johnennew » yesct

(@cend I think it's ok to assign it to me, it's been a while. :) I have some changes I'll post after I go through the rest.)

yesct’s picture

oops. meant to save this comment I had open in another window earlier.
--
I started reviewing this. It is a lot to read through.

in #35 by @ceng

This leaves the $comment->is_anonymous and $comment->is_preview variables still to tidy up. I think this patch is good to go if these are moved out to follow up issues, the patch is getting quite big with a number of changes.

grepping for is_anonymous and is_preview I dont see is_preview at all, and in
core/modules/comment/lib/Drupal/comment/CommentFormController.php

213:    $form['is_anonymous'] = array(
280:      if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) {
284:    elseif ($form_state['values']['is_anonymous']) {
322:    if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
327:    if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {

These were also discussed in #26, #27, and @Berdir says in #28

If that's the case, then I doubt that's set. The NG (now ContentEntity) form controller only sets explicitly defined fields, everything else is ignored. You have to override and extend buildEntity() to set more stuff, see NodeFormController.

The patch has no instances of is_anonymous and is_preview, so it wasn't this patch that took it out. Maybe it was another issue.

I'll create an issue as was mentioned and we can sort it out there. Here it is #2170439: $comment->is_anonymous and $comment->is_preview variable should be removed or converted to be explicit properties with getter and setter menthods

I'll keep going with the review. I have a few small changes so far.
--
also started updating issue summary.

yesct’s picture

Assigned: yesct » Unassigned
StatusFileSize
new5.09 KB
new102.88 KB
  1. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -26,6 +26,257 @@
    +   * Determine if this comment is a reply to another comment.
    ...
    +   * Set the field ID for which this commment is attached.
    

    I changed a few first line function summaries to be third person verbs.

  2. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -26,6 +26,257 @@
    +   * Returns the title of the comment.
    +   *
    +   * @return string
    +   *   The title of the comment.
    +   */
    +  public function getSubject();
    

    read a little strange that the docs mentioned title and not subject. larowlan suggested checking what the column is called in {comments} table in comment_schema, which is in comment.install It is 'subject'. So changing the docs.

  3. +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
    @@ -273,8 +273,8 @@ protected function alterBuild(array &$build, EntityInterface $comment, EntityVie
    -      $commented_entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value);
    -      $instance = $this->fieldInfo->getInstance($commented_entity->entityType(), $commented_entity->bundle(), $comment->field_name->value);
    +      $commented_entity = $this->entityManager->getStorageController($comment->getCommentedEntityType())->load($comment->getCommentedEntityId());
    +      $instance = $this->fieldInfo->getInstance($commented_entity->entityType(), $commented_entity->bundle(), $comment->getFieldName());
    

    This made me wonder if $commented_entity->entityType() should become $comment->getCommentedEntityType(). I decided it wasn't necessary and I didn't change it.

  4. +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
    @@ -236,8 +236,8 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
    -        // 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())) {
    +        // Check if the parent comment is published and belongs to the current nid.
    +        if (!$comment->isPublished() || ($comment->getCommentedEntityId() != $entity->id())) {
    

    changing that comment from entity to current nid seems out of place. I dont think it is node specific. changing comment back.

  5. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -281,24 +130,24 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
    -      if (empty($this->changed->value)) {
    -        $this->changed->value = $this->created->value;
    +      if (is_null($this->getChangedTime())) {
    +        $this->set('changed', $this->getCreatedTime());
    

    seems like this should be:
    $this->setChangedTime($this->getCreatedTime()); Oh, but I see in comment #5 @berdir mentioned something related. and this is in preSave(). Ok.

I stopped at CommentActionTest

posting the patch so far, and taking a break.

yesct’s picture

coming back to try and finish review.

yesct’s picture

Issue summary: View changes
Related issues: +#2078387: Add an EntityOwnerInterface

trying to clarify what is *not* being done in this issue, and why. please edit the summary and fill out the why where the reason is missing.

yesct’s picture

  1. +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php
    @@ -75,24 +75,24 @@ function testCommentInterface() {
    -    $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->getUsername()));
    -    $this->assertTrue($comment->name->value == $this->web_user->getUsername() && $comment->uid->target_id == $this->web_user->id(), 'Comment author successfully changed to a registered user.');
    +    $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => $this->web_user->getUsername()));
    +    $this->assertTrue($comment->getAuthorName() == $this->web_user->getUsername() && $comment->uid->target_id == $this->web_user->id(), 'Comment author successfully changed to a registered user.');
    

    I think $comment->uid->target_id in the assert should be $comment->getAuthorId()

  2. +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php
    @@ -106,7 +106,7 @@ function testCommentNodeCommentStatistics() {
    -    $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->name->value, 'The value of node last_comment_name is the name of the anonymous user.');
    +    $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->getAuthorName(), 'The value of node last_comment_name is the name of the anonymous user.');
         $this->assertEqual($node->get('comment')->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
         $this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.');
    

    seems strange to be doing these direct access to properties. but I see them set in comment.module (around line 912).

phew. read the whole thing.

next, I wanted to try the hint for patch producers in the meta which says "Ideally the visibility of the properties which are getters and setters in this case can force people to use the property directly and instead of using it directly, use it as a method so while working on the patch you can make the visibility as protected and change them back to public before RTBC"

But that is assuming there are properties. And here, looks like ->set(' ') and ->get(' ') are used not properties that could be set to protected.

So I guess I cannot make a patch that can "check" we have gotten all the replacements and not missed any. ... maybe a grep could be done?

might as well guess at something...
$ ag "comment\-\>" core

A:
comment.module template_preprocess_comment()

1481:  if (!$comment->uid->target_id) {
1486:    if ($commented_entity->hasField('uid') && $comment->uid->target_id == $commented_entity->get('uid')->value) {

should use getAuthorId() ?

as mentioned previously #2078387: Add an EntityOwnerInterface might do them? but maybe we should change there here too, and then at least they are all done, and the which ever issue gets in first can go, and the other can be rerolled to account for that.

B:
in CommentFormController form()

139:      $date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value);

should that be getCreatedTime() ?

C:
in CommentFormController submit()

323:      $comment->uid->target_id = $account->id();

should use getAuthorId() ?

D:
in CommentFormController submit()

339:      $comment->subject = Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE);

should use setSubject() ?

E:
in CommentViewBuilder buildContent()

113:    // $comment->entity_id->value as we can load them in bulk per type.

should that comment be replaced with getCommentedEntity() ?
Like (line wrap would need correcting):

    // Load entities in bulk. This is more performant than using
    // $comment->getCommentedEntity() as we can load them in bulk per type.

or maybe
// Load entities in bulk. This is more performant than using
// $comment->entity_id->value or $comment->getCommentedEntity() as we can load them in bulk per type.

F:
in CommentAdminOverview in buildForm()

185:      $commented_entity_ids[$comment->entity_type->value][] = $comment->entity_id->value;

should that use getCommentedEntityType() and getCommentedEntityId() ?

G:
in core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php

117:      $entity_id = $comment->entity_id;
118:      $entity_type = $comment->entity_type;
(for context) 119:      $entity = $this->entityManager->getStorageController($entity_type)->load($entity_id);

Are these (entity_id and entity_type) going to cause a problem?

H:
in CommentCSSTest

135:        $this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->changed->value . '"]')), 'data-comment-timestamp attribute is set on comment');

Should that be getChangedTime() ?

I:
In CommentLinksTest

169:    if ($this->node->comment->status != $info['comments']) {
239:            if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
241:              $this->comment->seen = TRUE;
254:        $this->comment->seen = TRUE;

->status, if that were ->status->value, I would say it should be ->isPublished() But I'm not sure.

->seen ? huh? is that just in this test, and so can be ignored?

J:
in CommentNewIndicatorTest

114:    $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->changed->value .  '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.');

K:
in core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php

249:      'value' => $comment->subject->value,
257:      'value' => date('c', $comment->created->value),
264:      'value' => date('c', $comment->created->value),
278:    if ($comment->uid->value > 0) {
279:      $author_uri = url('user/' . $comment->uid->value, array('absolute' => TRUE));
307:    if ($comment->uid->value == 0) {

Looks like these were missed?

L:
in rdf.module

494:    if ($comment->pid->target_id != 0) {

Looks like this should be getParentComment()->id()

M:
in EntityCrudHookTest

191:    $comment->subject->value = 'New subject';

is this direct set of subject ok? CommentTokenReplaceTest uses setSubject(). Maybe this should also?

N:
in tracker.module

291:  if ($latest_comment && $latest_comment->changed > $changed) {
292:    $changed = $latest_comment->changed;

Should that use getChangedTime() ?

berdir’s picture

Wow, lot's of letters.

#77

2. This is information on the comment field on a node, not comment entity. So that's OK, don't touch that stuff.

A) Hm, author interface provides a clean solution for the whole hunk, this would just change the hack a bit. I'd rather avoid commit conflicts.

B) Yes.

C) set...(), but also taken care of in the AuthorInterface issue I think.

D) Should probably live somewhere else but yes, setSubject()

E) Yes, just method is fine.

F) Yes.

G) Cases where there is no ->value are special, there two reasons for that: a) It is broken and untested (because it's then working with an object) b) It is not a comment entity object, but something else, like a raw fetched database row. Checking the context, and seeing the argument type hint and $comment->id() above, we know it is a) in this case. Should use the method and should have a follow-up to add test coverage for this code block.

H) Yes.

I) Another case of a comment field, you can see that it's $this->node->comment, not $this->comment or $comment, so it's part of a node object and a different kind of status. Ok. ->seen is also ok (at least in this context)

J) Yes, same as H)

K) Yes, should be updated too. I guess this test is newer than the early patches.

L) There is a specific method for these checks: hasParentComment(), see other uses of that method.

M) Well, it's OK in "it works", but as you found it, let's replace it too, yes.

N) See G), in this case, it's b), tracker.module still has a lot of direct database queries and raw value objects, so don't touch it here.

berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

EntityOwnerInterface landed (yay!), so this will need a pretty tough re-roll). This might not be the one you want to pick if you're doing your first re-roll :) I'll see if I have time to do it and also apply the points above.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new101.03 KB

Here's a re-roll, probably messed up a few things, will also need more work after recent renames and I have some ideas on how improve this further, but enough for tonight.

Was hoping this would get a bit smaller, but most author/owner changes have additional changes around the. It's also a bit a mess of author and owner now... :(

Status: Needs review » Needs work

The last submitted patch, 80: comment-interface-2028025.80.patch, failed testing.

The last submitted patch, 80: comment-interface-2028025.80.patch, failed testing.

yesct’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new100.69 KB
new738 bytes

Not sure if @Berdir had a different place to put this hunk... but it didn't go there. :)

edit: I also diffed the patches 74 and 80 and noticed these couple niffty improvements

1.

< +  $entity = entity_load($comment->getCommentedEntityType(), $comment->getCommentedEntityId());
> +  $entity = $comment->getCommentedEntity();

berdir says:
saves code and avoids a call out to that function
so unit tests or so would be easier/possible

2.

> -  if ($entity->getEntityTypeId() == 'comment') {
> +  if ($entity instanceof CommentInterface) {

Status: Needs review » Needs work

The last submitted patch, 83: comment-interface-2028025.83.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new113.73 KB
new32.83 KB

Ok, I think this should fix those test fails and I also tried to address everything that was pointed out above and a few more.

Status: Needs review » Needs work

The last submitted patch, 85: comment-interface-2028025.85.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new114.46 KB
new3.33 KB

Ups.

yesct’s picture

Issue summary: View changes

I looked at the interdiffs in #85 and #87 And they look great.

Issues to open for later might be
#78 D (a minor should live else where),
#78 G (needs fix and test coverage)
added to issue summary.

Updated issue summary especially regarding possible issues to be opened (not necessarily "follow-ups", but to be opened.)

Looking really good. What's next? One more final look by.. ? @larowlan

[edit:] I didn't delete those. See #2191619: New on-page comment form is deleting all hidden files :(

andypost’s picture

berdir’s picture

Thanks @YesCT. Note that D and G *are* addressed as far as this patch is relevant for them (changed to method calls, fixing the bug in case of G), but doesn't add test coverage.

andypost’s picture

Issue summary: View changes

Updated summary about permalink #2113323: Rename Comment::permalink() to not be ambiguous with ::uri()
Issue is RTBC and needs change notice draft, suppose @larowlan will fire rtbc and set 'avoid commit conflicts'

yesct’s picture

Issue summary: View changes

@Berdir, ah yes. :)

tiny issue summary clarifications.

I'll start a draft change record. (following https://drupal.org/contributor-tasks/draft-change-record)
[update]
Actually "New Entity Field API based upon the Typed Data API" https://drupal.org/node/1806650 covers this and the meta is already listed there.
@Berdir says we dont need to clutter that with each one of the sub issues.
Looked for an example in one of the others for what to do. In #2028037-53: Expand FeedInterface with methods @webchick says

We'll need to scour existing change notices to make sure they reflect the methods introduced here.

Maybe what we can do here is list the change records that we edit.
"Comment settings are now a field. Comments allowed on any entity type." https://drupal.org/node/2100015 might be one.

larowlan’s picture

  1. +++ b/core/modules/comment/comment.module
    @@ -1293,13 +1294,14 @@ function comment_preview(CommentInterface $comment, array &$form_state) {
    +      $comment->setAuthorName(check_plain($account->getUsername()));
    
    +++ b/core/modules/comment/comment.tokens.inc
    @@ -137,32 +137,27 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    +          $replacements[$original] = $sanitize ? check_plain($comment->getHostname()) : $comment->getHostname();
    ...
    +          $replacements[$original] = $sanitize ? filter_xss($comment->getSubject()) : $comment->getSubject();
    
    @@ -180,28 +175,31 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
    +          $replacements[$original] = $sanitize ? filter_xss($name) : $name;
    ...
    +            $replacements[$original] = $sanitize ? filter_xss($parent->getSubject()) : $parent->getSubject();
    

    would have been nice to use String::checkPlain and the corresponding XSS util while touching these lines, but unless we need another reroll, leave as is

  2. +++ b/core/modules/comment/comment.module
    @@ -1480,7 +1482,7 @@ function template_preprocess_comment(&$variables) {
    +    $variables['status'] = $comment->isPublished() ? 'published' : 'unpublished';
    

    out of scope: missing t() here, please fix if re-rolling

  3. +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
    @@ -79,8 +79,8 @@ protected function init(array &$form_state) {
    +    $entity = $this->entityManager->getStorageController($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());
    
    @@ -232,8 +232,8 @@ public function form(array $form, array &$form_state) {
    +    $entity = $this->entityManager->getStorageController($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());
    

    Can this use CommentInterface::getCommentedEntity now?

  4. +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
    @@ -320,28 +320,29 @@ public function submit(array $form, array &$form_state) {
    +    if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
    

    Mental note: we need to inject the User storage controller here (needs follow up).

  5. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -27,6 +27,231 @@
    +   * @return \Drupal\Core\Entity\EntityInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    ...
    +   * @return \Drupal\comment\CommentInterface
    

    I believe new coding standard is these should just say @return $this with no description/other comments

  6. +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
    @@ -27,6 +27,231 @@
    +  /**
    +   * Returns the field ID of the comment field the comment is attached to.
    +   *
    +   * @return string
    +   *   The field identifier of the field the comment is attached to.
    +   */
    +  public function getFieldId();
    

    i don't think this is any different to CommentInterface::bundle(), I think we can replace all calls with ::bundle() instead and remove the duplication?

  7. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -60,156 +60,7 @@ class Comment extends ContentEntityBase implements CommentInterface {
    -   * The comment ID.
    -   *
    -   * @var \Drupal\Core\Field\FieldItemListInterface
    -   */
    -  public $cid;
    -
    -  /**
    -   * The comment UUID.
    -   *
    -   * @var \Drupal\Core\Field\FieldItemListInterface
    -   */
    -  public $uuid;
    -
    -  /**
    -   * The parent comment ID if this is a reply to another comment.
    -   *
    -   * @var \Drupal\Core\Field\FieldItemListInterface
    -   */
    -  public $pid;
    -
    -  /**
    -   * The entity ID for the entity to which this comment is attached.
    -   *
    -   * @var \Drupal\Core\Field\FieldItemListInterface
    -   */
    -  public $entity_id;
    -
    

    love it!

  8. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -221,23 +72,21 @@ public function id() {
    +        if (! $this->hasParentComment()) {
    

    extra space?

  9. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -280,24 +129,24 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
    -      $this->hostname->value = \Drupal::request()->getClientIP();
    
    @@ -452,8 +301,192 @@ public static function baseFieldDefinitions($entity_type) {
    +    return entity_load($entity_type, $entity_id);
    

    Mental note: we really need to be able to inject into Entity classes. entity_load (puke)

  10. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -343,7 +192,7 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
    -    $entity = entity_load($this->get('entity_type')->value, $this->get('entity_id')->value);
    +    $entity = $this->getCommentedEntity();
    

    schmick!

  11. +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php
    @@ -114,8 +115,8 @@ protected function renderLink($data, ResultRow $values) {
    -      $entity_id = $comment->entity_id;
    -      $entity_type = $comment->entity_type;
    +      $entity_id = $comment->getCommentedEntityId();
    +      $entity_type = $comment->getCommentedEntityTypeId();
           $entity = $this->entityManager->getStorageController($entity_type)->load($entity_id);
    

    Can be simplified to CommentInterface::getCommentedEntity()?

berdir’s picture

1. Hm, looked at it, but we only touch a part of those lines, so I'd prefer to leave it for this issue.
2. This is used as a css class, so no :)
3. Yes :)
4. Yeah, note that the code will look a fair bit more complicated then, though, because there's no loadByName() method.
5. We do. Fixed. I did leave it on getParentComment(), because that's a different comment. Same for getCommentedEntity().
6. We had quite some discussions on the node issue related to this and came to the conclusion that it makes sense to have node specific getType() and getTitle() methods there, because they often make much more sense in a context where you have a comment and are working with that specific field. For example, someMethod($comment->getFieldId()) explains itself much better than someMethod($comment->bundle()), then you first have to know what the bundle actually is. Term doesn't follow that, but that's because it happened before the discussion in the node issue. We also have getSubject() and don't use label() here.
8. Fixed
11. Yes :)

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Avoid commit conflicts

Assuming bot agrees

alexpott’s picture

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

comment-interface-2028025.94.patch no longer applies.

error: patch failed: core/modules/tracker/tracker.module:206
error: core/modules/tracker/tracker.module: patch does not apply

berdir’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new114.17 KB
new3.96 KB

Re-roll, conflicted as expected in tracker.module, this just re-replaces the changed code with the method, so only changes in the removed code, see attached patch diff.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 97: comment-interface-2028025.97.patch, failed testing.

berdir’s picture

yesct’s picture

Status: Needs work » Needs review

looks like this passed the testbot. so setting to needs review.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

I think we can go back RTBC here, there's a diff above that should that nothing in the patch actually changed, only the previous code did.

xjm’s picture

Draft change records are now required before commit. I searched for CommentInterface in the existing change records and none of the matches for that will need an update.

+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -60,156 +60,7 @@ class Comment extends ContentEntityBase implements CommentInterface {
-  public $cid;
...
-  public $uuid;
...
-  public $pid;
...
-  public $entity_id;
...
-  public $entity_type;
...
-  public $field_id;
...
-  public $langcode;
...
-  public $subject;
...
-  public $uid;
...
-  public $name;
...
-  public $mail;
...
-  public $homepage;
...
-  public $hostname;
...
-  public $created;
...
-  public $changed;
...
-  public $status;
...
-  public $thread;

So I think these are all the deleted thingers that we'd need to search the change records for?

https://drupal.org/node/2100015 only references comment count, which is not changed per the summary, so that one is still okay I think.

alexpott’s picture

xjm’s picture

@alexpott asked me about #102 and whether I deliberately didn't set the issue NW. To clarify, I was replying to @YesCT's comments in #92. https://drupal.org/node/1806650 is the change record for the meta and is nicely written to cover all these changes, linking off to the API documentation, so this issue already is covered as far as change records go. (Though, that change record needs to have a reference to this issue added.)

It would be good for someone to look around a little in comment change records for references to the removed comment member variables in #102, but based on my review of what's currently there, I think that need not block commit and the issue is still RTBC.

andypost’s picture

alexpott’s picture

Priority: Normal » Major
Status: Reviewed & tested by the community » Fixed
Issue tags: -Avoid commit conflicts

The DX win means that this should be major. Can someone add this issue to https://drupal.org/node/1806650?

Committed f3732c6 and pushed to 8.x. Thanks!

andypost’s picture

berdir’s picture

Note: I suggested to not add this issue to that change notice before, because this is part of a meta issue that is already referenced, adding every single issue in there would mean that we add like 10 additional issues and there are already a lot. This conversion is not that relevant compared to a lot of the other issues referenced there.

Status: Fixed » Closed (fixed)

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