Commit 000dbabc authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3015697 by alexpott, andypost: Properly deprecate COMMENT_ANONYMOUS_* constants

parent 012172e5
Loading
Loading
Loading
Loading
+1 −1
Changes for core/modules/comment/src/CommentAccessControlHandler.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_
        $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()))
+5 −5
Changes for core/modules/comment/src/CommentForm.php: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public function form(array $form, FormStateInterface $form_state) {
    $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 @@ public function form(array $form, FormStateInterface $form_state) {
      '#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 @@ public function form(array $form, FormStateInterface $form_state) {
      '#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 @@ public function form(array $form, FormStateInterface $form_state) {
      '#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.
+5 −4
Changes for core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ public static function defaultFieldSettings() {
      '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 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
      '#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'),
    ];
+1 −1
Changes for core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public function validate($entity, Constraint $constraint) {
    // 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();
+4 −3
Changes for core/modules/comment/tests/src/Functional/CommentAnonymousTest.php: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\comment\Functional;

use Drupal\comment\CommentInterface;
use Drupal\user\RoleInterface;

/**
@@ -32,7 +33,7 @@ protected function setUp() {
   */
  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 @@ public function testAnonymous() {

    // 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 @@ public function testAnonymous() {

    // 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).
Loading