.../Field/FieldWidget/EmailDefaultWidget.php | 3 ++ .../lib/Drupal/comment/CommentFormController.php | 34 +++++++++------------- .../comment/lib/Drupal/comment/Entity/Comment.php | 20 +++++++++++-- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php index 889fbab..333caa6 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php @@ -29,6 +29,7 @@ class EmailDefaultWidget extends WidgetBase { public static function defaultSettings() { return array( 'placeholder' => '', + 'size' => 60, ) + parent::defaultSettings(); } @@ -70,6 +71,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#type' => 'email', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#placeholder' => $this->getSetting('placeholder'), + '#size' => $this->getSetting('size'), + '#maxlength' => $this->getFieldSetting('max_length'), ); return $element; } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 8deed69..cabdac2 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -116,7 +116,9 @@ public function form(array $form, array &$form_state) { $form += $form_state['comment_preview']; } - $form['author'] = array(); + $form['author'] = array( + '#weight' => -5, + ); // Display author information in a details element for comment moderators. if ($is_admin) { $form['author'] += array( @@ -157,6 +159,7 @@ public function form(array $form, array &$form_state) { '#default_value' => $author, '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT), '#maxlength' => 60, + '#weight' => -20, '#size' => 30, ); if ($is_admin) { @@ -172,25 +175,16 @@ public function form(array $form, array &$form_state) { } // Add author e-mail and homepage fields depending on the current user. - $form['author']['mail'] = array( - '#type' => 'email', - '#title' => $this->t('E-mail'), - '#default_value' => $comment->getAuthorEmail(), - '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_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' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT), - ); - - $form['author']['homepage'] = array( - '#type' => 'url', - '#title' => $this->t('Homepage'), - '#default_value' => $comment->getHomepage(), - '#maxlength' => 255, - '#size' => 30, - '#access' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT), - ); + $form['author']['mail'] = $form['mail']; + unset($form['mail']); + $form['author']['mail']['widget'][0]['value']['#description'] = $this->t('The content of this field is kept private and will not be shown publicly.'); + $form['author']['mail']['widget'][0]['value']['#required'] = ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT); + $form['author']['mail']['widget'][0]['value']['#access'] = $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT); + + $form['author']['homepage'] = $form['homepage']; + unset($form['homepage']); + unset($form['author']['homepage']['widget'][0]['value']['#description']); + $form['author']['homepage']['widget'][0]['value']['#access'] = $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT); // Add administrative comment publishing options. $form['author']['date'] = array( diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 4192669..c5d56da 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -259,21 +259,35 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setConstraints(array('CommentName' => array())); $fields['mail'] = FieldDefinition::create('email') - ->setLabel(t('Email')) - ->setDescription(t("The comment author's e-mail address.")); + ->setLabel(t('E-mail')) + ->setDescription(t("The comment author's e-mail address.")) + ->setSetting('max_length', 64) + ->setDisplayOptions('form', array( + 'type' => 'email_default', + 'weight' => -10, + 'settings' => array( + 'size' => 30, + ), + )); $fields['homepage'] = FieldDefinition::create('uri') ->setLabel(t('Homepage')) ->setDescription(t("The comment author's home page address.")) // URIs are not length limited by RFC 2616, but we can only store 255 // characters in our comment DB schema. - ->setSetting('max_length', 255); + ->setSetting('max_length', 255) + ->setDisplayOptions('form', array( + 'type' => 'uri', + 'size' => 30, + 'weight' => -5, + )); $fields['hostname'] = FieldDefinition::create('string') ->setLabel(t('Hostname')) ->setDescription(t("The comment author's hostname.")) ->setSetting('max_length', 128); + // @todo: use timestamp widget after https://drupal.org/node/2226493 lands. $fields['created'] = FieldDefinition::create('created') ->setLabel(t('Created')) ->setDescription(t('The time that the comment was created.'));