Issue #3015697 by alexpott, andypost: Properly deprecate COMMENT_ANONYMOUS_* constants
							parent
							
								
									012172e51e
								
							
						
					
					
						commit
						000dbabc57
					
				| 
						 | 
				
			
			@ -126,7 +126,7 @@ class CommentAccessControlHandler extends EntityAccessControlHandler {
 | 
			
		|||
        $commented_entity = $entity->getCommentedEntity();
 | 
			
		||||
        $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 || $is_name) && $account->hasPermission('post comments'))
 | 
			
		||||
        $anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && ($anonymous_contact != CommentInterface::ANONYMOUS_MAYNOT_CONTACT || $is_name) && $account->hasPermission('post comments'))
 | 
			
		||||
          ->cachePerPermissions()
 | 
			
		||||
          ->addCacheableDependency($entity)
 | 
			
		||||
          ->addCacheableDependency($field_definition->getConfig($commented_entity->bundle()))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,7 +108,7 @@ class CommentForm extends ContentEntityForm {
 | 
			
		|||
    $anonymous_contact = $field_definition->getSetting('anonymous');
 | 
			
		||||
    $is_admin = $comment->id() && $this->currentUser->hasPermission('administer comments');
 | 
			
		||||
 | 
			
		||||
    if (!$this->currentUser->isAuthenticated() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
 | 
			
		||||
    if (!$this->currentUser->isAuthenticated() && $anonymous_contact != CommentInterface::ANONYMOUS_MAYNOT_CONTACT) {
 | 
			
		||||
      $form['#attached']['library'][] = 'core/drupal.form';
 | 
			
		||||
      $form['#attributes']['data-user-info-from-browser'] = TRUE;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -178,7 +178,7 @@ class CommentForm extends ContentEntityForm {
 | 
			
		|||
      '#type' => 'textfield',
 | 
			
		||||
      '#title' => $is_admin ? $this->t('Name for @anonymous', ['@anonymous' => $config->get('anonymous')]) : $this->t('Your name'),
 | 
			
		||||
      '#default_value' => $author,
 | 
			
		||||
      '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
 | 
			
		||||
      '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == CommentInterface::ANONYMOUS_MUST_CONTACT),
 | 
			
		||||
      '#maxlength' => 60,
 | 
			
		||||
      '#access' => $this->currentUser->isAnonymous() || $is_admin,
 | 
			
		||||
      '#size' => 30,
 | 
			
		||||
| 
						 | 
				
			
			@ -202,11 +202,11 @@ class CommentForm extends ContentEntityForm {
 | 
			
		|||
      '#type' => 'email',
 | 
			
		||||
      '#title' => $this->t('Email'),
 | 
			
		||||
      '#default_value' => $comment->getAuthorEmail(),
 | 
			
		||||
      '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
 | 
			
		||||
      '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == CommentInterface::ANONYMOUS_MUST_CONTACT),
 | 
			
		||||
      '#maxlength' => 64,
 | 
			
		||||
      '#size' => 30,
 | 
			
		||||
      '#description' => $this->t('The content of this field is kept private and will not be shown publicly.'),
 | 
			
		||||
      '#access' => ($comment->getOwner()->isAnonymous() && $is_admin) || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
 | 
			
		||||
      '#access' => ($comment->getOwner()->isAnonymous() && $is_admin) || ($this->currentUser->isAnonymous() && $anonymous_contact != CommentInterface::ANONYMOUS_MAYNOT_CONTACT),
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    $form['author']['homepage'] = [
 | 
			
		||||
| 
						 | 
				
			
			@ -215,7 +215,7 @@ class CommentForm extends ContentEntityForm {
 | 
			
		|||
      '#default_value' => $comment->getHomepage(),
 | 
			
		||||
      '#maxlength' => 255,
 | 
			
		||||
      '#size' => 30,
 | 
			
		||||
      '#access' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
 | 
			
		||||
      '#access' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != CommentInterface::ANONYMOUS_MAYNOT_CONTACT),
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    // Add administrative comment publishing options.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace Drupal\comment\Plugin\Field\FieldType;
 | 
			
		||||
 | 
			
		||||
use Drupal\comment\CommentInterface;
 | 
			
		||||
use Drupal\comment\CommentManagerInterface;
 | 
			
		||||
use Drupal\comment\Entity\CommentType;
 | 
			
		||||
use Drupal\Core\Field\FieldDefinitionInterface;
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +45,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
 | 
			
		|||
      'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED,
 | 
			
		||||
      'per_page' => 50,
 | 
			
		||||
      'form_location' => CommentItemInterface::FORM_BELOW,
 | 
			
		||||
      'anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
 | 
			
		||||
      'anonymous' => CommentInterface::ANONYMOUS_MAYNOT_CONTACT,
 | 
			
		||||
      'preview' => DRUPAL_OPTIONAL,
 | 
			
		||||
    ] + parent::defaultFieldSettings();
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -124,9 +125,9 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
 | 
			
		|||
      '#title' => t('Anonymous commenting'),
 | 
			
		||||
      '#default_value' => $settings['anonymous'],
 | 
			
		||||
      '#options' => [
 | 
			
		||||
        COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'),
 | 
			
		||||
        COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'),
 | 
			
		||||
        COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'),
 | 
			
		||||
        CommentInterface::ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'),
 | 
			
		||||
        CommentInterface::ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'),
 | 
			
		||||
        CommentInterface::ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'),
 | 
			
		||||
      ],
 | 
			
		||||
      '#access' => $anonymous_user->hasPermission('post comments'),
 | 
			
		||||
    ];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ class CommentNameConstraintValidator extends ConstraintValidator implements Cont
 | 
			
		|||
    // can't validate this without a valid commented entity, which will fail
 | 
			
		||||
    // the validation elsewhere.
 | 
			
		||||
    if ($owner_id === 0 && empty($author_name) && $entity->getCommentedEntity() && $entity->getFieldName() &&
 | 
			
		||||
      $this->getAnonymousContactDetailsSetting($entity) === COMMENT_ANONYMOUS_MUST_CONTACT) {
 | 
			
		||||
      $this->getAnonymousContactDetailsSetting($entity) === CommentInterface::ANONYMOUS_MUST_CONTACT) {
 | 
			
		||||
      $this->context->buildViolation($constraint->messageRequired)
 | 
			
		||||
        ->atPath('name')
 | 
			
		||||
        ->addViolation();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace Drupal\Tests\comment\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\comment\CommentInterface;
 | 
			
		||||
use Drupal\user\RoleInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +33,7 @@ class CommentAnonymousTest extends CommentTestBase {
 | 
			
		|||
   */
 | 
			
		||||
  public function testAnonymous() {
 | 
			
		||||
    $this->drupalLogin($this->adminUser);
 | 
			
		||||
    $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAYNOT_CONTACT);
 | 
			
		||||
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
 | 
			
		||||
    $this->drupalLogout();
 | 
			
		||||
 | 
			
		||||
    // Preview comments (with `skip comment approval` permission).
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +78,7 @@ class CommentAnonymousTest extends CommentTestBase {
 | 
			
		|||
 | 
			
		||||
    // Allow contact info.
 | 
			
		||||
    $this->drupalLogin($this->adminUser);
 | 
			
		||||
    $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
 | 
			
		||||
    // Attempt to edit anonymous comment.
 | 
			
		||||
    $this->drupalGet('comment/' . $anonymous_comment1->id() . '/edit');
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +111,7 @@ class CommentAnonymousTest extends CommentTestBase {
 | 
			
		|||
 | 
			
		||||
    // Require contact info.
 | 
			
		||||
    $this->drupalLogin($this->adminUser);
 | 
			
		||||
    $this->setCommentAnonymous(COMMENT_ANONYMOUS_MUST_CONTACT);
 | 
			
		||||
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MUST_CONTACT);
 | 
			
		||||
    $this->drupalLogout();
 | 
			
		||||
 | 
			
		||||
    // Try to post comment with contact info (required).
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -396,14 +396,14 @@ class CommentNonNodeTest extends BrowserTestBase {
 | 
			
		|||
    // Test comment option change in field settings.
 | 
			
		||||
    $edit = [
 | 
			
		||||
      'default_value_input[comment][0][status]' => CommentItemInterface::CLOSED,
 | 
			
		||||
      'settings[anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT,
 | 
			
		||||
      'settings[anonymous]' => CommentInterface::ANONYMOUS_MAY_CONTACT,
 | 
			
		||||
    ];
 | 
			
		||||
    $this->drupalPostForm(NULL, $edit, t('Save settings'));
 | 
			
		||||
    $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
 | 
			
		||||
    $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
 | 
			
		||||
    $this->assertFieldChecked('edit-default-value-input-comment-0-status-1');
 | 
			
		||||
    $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
 | 
			
		||||
    $this->assertFieldByName('settings[anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $this->assertFieldByName('settings[anonymous]', CommentInterface::ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
 | 
			
		||||
    // Add a new comment-type.
 | 
			
		||||
    $bundle = CommentType::create([
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace Drupal\Tests\comment\Kernel;
 | 
			
		||||
 | 
			
		||||
use Drupal\comment\CommentInterface;
 | 
			
		||||
use Drupal\comment\Entity\Comment;
 | 
			
		||||
use Drupal\comment\Entity\CommentType;
 | 
			
		||||
use Drupal\comment\Tests\CommentTestTrait;
 | 
			
		||||
| 
						 | 
				
			
			@ -142,7 +143,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
 | 
			
		|||
    // Change the second field's anonymous contact setting.
 | 
			
		||||
    $instance = FieldConfig::loadByName('entity_test', 'entity_test', 'comment_other');
 | 
			
		||||
    // Default is 'May not contact', for this field - they may contact.
 | 
			
		||||
    $instance->setSetting('anonymous', COMMENT_ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $instance->setSetting('anonymous', CommentInterface::ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $instance->save();
 | 
			
		||||
 | 
			
		||||
    // Create three "Comments". One is owned by our edit-enabled user.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -135,7 +135,7 @@ class CommentValidationTest extends EntityKernelTestBase {
 | 
			
		|||
    $comment->set('thread', NULL);
 | 
			
		||||
 | 
			
		||||
    // Force anonymous users to enter contact details.
 | 
			
		||||
    $field->setSetting('anonymous', COMMENT_ANONYMOUS_MUST_CONTACT);
 | 
			
		||||
    $field->setSetting('anonymous', CommentInterface::ANONYMOUS_MUST_CONTACT);
 | 
			
		||||
    $field->save();
 | 
			
		||||
    // Reset the node entity.
 | 
			
		||||
    \Drupal::entityManager()->getStorage('node')->resetCache([$node->id()]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,7 +46,7 @@ class CommentAttributesTest extends CommentTestBase {
 | 
			
		|||
      'skip comment approval' => TRUE,
 | 
			
		||||
    ]);
 | 
			
		||||
    // Allows anonymous to leave their contact information.
 | 
			
		||||
    $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);
 | 
			
		||||
    $this->setCommentPreview(DRUPAL_OPTIONAL);
 | 
			
		||||
    $this->setCommentForm(TRUE);
 | 
			
		||||
    $this->setCommentSubject(TRUE);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue