diff --git a/core/modules/comment/src/CommentAccessControlHandler.php b/core/modules/comment/src/CommentAccessControlHandler.php index 7d6504c9e51acecd9c618f1b73453b06e44cc7d9..1706c85f43020454521421f75bd13733e02c99f2 100644 --- a/core/modules/comment/src/CommentAccessControlHandler.php +++ b/core/modules/comment/src/CommentAccessControlHandler.php @@ -100,7 +100,7 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_ /** @var \Drupal\comment\CommentInterface $entity */ $entity = $items->getEntity(); $commented_entity = $entity->getCommentedEntity(); - $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous_contact'); + $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous'); $admin_access = AccessResult::allowedIfHasPermission($account, 'administer comments'); $anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT && $account->hasPermission('post comments')) ->cachePerRole() diff --git a/core/modules/comment/src/Tests/CommentFieldAccessTest.php b/core/modules/comment/src/Tests/CommentFieldAccessTest.php index 2d895e3cf921d495ba2632b7f197d1a2e5431d1e..c6cd2d2d681316e36dd261a42e87a891c09e5f35 100644 --- a/core/modules/comment/src/Tests/CommentFieldAccessTest.php +++ b/core/modules/comment/src/Tests/CommentFieldAccessTest.php @@ -40,7 +40,6 @@ class CommentFieldAccessTest extends EntityUnitTestBase { 'uid', 'status', 'created', - 'name', ); /** @@ -135,7 +134,8 @@ public function testAccessToAdministrativeFields() { // Change the second field's anonymous contact setting. $instance = FieldConfig::loadByName('entity_test', 'entity_test', 'comment_other'); - $instance->settings['anonymous'] = COMMENT_ANONYMOUS_MAYNOT_CONTACT; + // Default is 'May not contact', for this field - they may contact. + $instance->settings['anonymous'] = COMMENT_ANONYMOUS_MAY_CONTACT; $instance->save(); // Create three "Comments". One is owned by our edit-enabled user. @@ -263,7 +263,7 @@ public function testAccessToAdministrativeFields() { $set['user']->isAnonymous() && $set['comment']->isNew() && $set['user']->hasPermission('post comments') && - $set['comment']->getFieldName() != 'comment_other' + $set['comment']->getFieldName() == 'comment_other' ), String::format('User @user !state update field !field on comment @comment', [ '@user' => $set['user']->getUsername(), '!state' => $may_update ? 'can' : 'cannot',