diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 7646837..b8c30d7 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -73,14 +73,14 @@ 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->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) { $form['#attached']['library'][] = 'core/drupal.form'; $form['#attributes']['data-user-info-from-browser'] = TRUE; } // If not replying to a comment, use our dedicated page callback for new // Comments on entities. - if (!$comment->id() && !$comment->hasParentComment()) { + if ($comment->isNew() && !$comment->hasParentComment()) { $form['#action'] = $this->url('comment.reply', array('entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), 'field_name' => $field_name)); } @@ -112,12 +112,12 @@ public function form(array $form, FormStateInterface $form_state) { } // Add the author name field depending on the current user. - $form['uid']['widget'][0]['value']['#required'] = ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT); - if ($this->currentUser->isAuthenticated()) { - $form['uid']['widget'][0]['value']['#type'] = 'item'; - $form['uid']['widget'][0]['value']['#value'] = $this->currentUser->id(); - $form['uid']['widget'][0]['value']['#theme'] = 'username'; - $form['uid']['widget'][0]['value']['#account'] = $this->currentUser; + $form['uid']['widget'][0]['target_id']['#required'] = ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT); + if ($this->currentUser->isAuthenticated() && !$is_admin) { + $form['uid']['widget'][0]['target_id']['#type'] = 'item'; + $form['uid']['widget'][0]['target_id']['#value'] = $this->currentUser->id(); + $form['uid']['widget'][0]['target_id']['#theme'] = 'username'; + $form['uid']['widget'][0]['target_id']['#account'] = $this->currentUser; } // Add author email and homepage fields depending on the current user. @@ -128,6 +128,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['homepage']['#group'] = 'author'; $form['created']['#group'] = 'author'; $form['name']['#group'] = 'author'; + // @todo Show the name only for admin and anonymous with setting. $form['author']['status'] = array( '#type' => 'radios', @@ -137,7 +138,7 @@ public function form(array $form, FormStateInterface $form_state) { CommentInterface::PUBLISHED => $this->t('Published'), CommentInterface::NOT_PUBLISHED => $this->t('Not published'), ), - '#access' => $comment->status->access('edit'), + '#access' => $is_admin, ); return $form; diff --git a/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php index 10e1af2..e3625b5 100644 --- a/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -26,7 +26,7 @@ * * @var array */ - public static $modules = array('comment', 'node', 'history', 'field_ui', 'datetime'); + public static $modules = array('comment', 'node', 'history', 'field_ui', 'datetime', 'entity_reference'); /** * An administrative user with permission to configure comment settings. diff --git a/core/modules/comment/src/Tests/CommentTranslationUITest.php b/core/modules/comment/src/Tests/CommentTranslationUITest.php index 2ae466a..6ee8525 100644 --- a/core/modules/comment/src/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/src/Tests/CommentTranslationUITest.php @@ -151,8 +151,8 @@ protected function doTestAuthoringInfo() { ); $edit = array( 'name[0][value]' => $user->getUsername(), - 'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), - 'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), + 'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), + 'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), ); $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode), array('language' => $languages[$langcode])); }