Updated: Comment #0

Problem/Motivation

Follow-up from #2028025: Expand CommentInterface to provide methods. That issue is close and not to be derailed with tidying up. This is the follow-up to discuss and take care of $comment->is_anonymous and $comment->is_preview variable

in 2028025 #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 core with the patch from 2028025 applied for is_anonymous and is_preview,
yields no result for is_preview at all,
and is_anonymous 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 === '')) {

which look like reads but not writes.

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.

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

Proposed resolution

remove or convert is_anonymous and is_preview to explicit properties with getters and setter methods.

Remaining tasks

  • figure out if there is some form magic that sets them
  • evaluate if we might have missing test coverage (in the case that those values are never set, why are we testing them in the ifs)

User interface changes

No

API changes

Maybe

Comments

rosinegrean’s picture

Hello,

I can try to work on this.

andypost’s picture

Seems only "is_anonymous" left to fix.

The following should get own issue

$ git grep is_preview
core/modules/node/node.api.php:215: * 'is_preview' field.
core/modules/node/node.api.php:223:  // Our module allows editors to mark specific articles with the 'is_preview'
core/modules/node/node.api.php:227:  if ($node->is_preview) {

The actual state

$ git grep is_anonymous
core/modules/comment/comment.module:593:    elseif (\Drupal::currentUser()->isAuthenticated() && empty($comment->is_anonymous)) {
core/modules/comment/src/CommentForm.php:215:    $form['is_anonymous'] = array(
core/modules/comment/src/CommentForm.php:272:      if ($form_state->getValue('name') && !$form_state->getValue('is_anonymous') && !$account) {
core/modules/comment/src/CommentForm.php:276:    elseif ($form_state->getValue('is_anonymous')) {
core/modules/comment/src/CommentForm.php:315:    if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
core/modules/comment/src/CommentForm.php:320:    if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:99:   * @param bool $is_anonymous
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:109:  public function testCommentLinkBuilder(NodeInterface $node, $context, $has_access_comments, $history_exists, $has_post_comments, $is_anonymous, $expected) {
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:122:      ->willReturn(!$is_anonymous);
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:125:      ->willReturn($is_anonymous);
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:192:      'is_anonymous' => array(FALSE, TRUE),
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:215:        $combination['is_anonymous'],
core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php:248:          elseif ($combination['is_anonymous']) {

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pjohans’s picture

Status: Active » Needs review

i have been looking at this issue and where it comes from https://www.drupal.org/node/2028025

the core/modules/comment/lib folder doesn't exist anymore.
the commentFormController file doesn't exist
methods is_preview and is_anonymous are only used in some tests

all in all i would say this issue is deprecated - it should be removed from the issue queue

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Closed (outdated)

Agree with #5 https://www.drupal.org/node/2028025 made this ticket obsolete

Berdir’s picture

Status: Closed (outdated) » Active

This issue is a follow-up of the one that's referenced. And the code was just moved around, it still exists, for example \Drupal\comment\CommentViewBuilder::alterBuild.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.