diff --git a/core/misc/form.js b/core/misc/form.js index f752f31..f1578bd 100644 --- a/core/misc/form.js +++ b/core/misc/form.js @@ -191,19 +191,29 @@ }; /** - * Prepopulate form fields with information from the visitor cookie. + * Prepopulate form fields with information from the visitor browser. */ - Drupal.behaviors.fillUserInfoFromCookie = { + Drupal.behaviors.fillUserInfoFromBrowser = { attach: function (context, settings) { var userInfo = ['name', 'mail', 'homepage']; - $('form.user-info-from-cookie').once('user-info-from-cookie', function () { + $('form.user-info-from-browser').once('user-info-from-browser', function () { var $formContext = $(this); - var i, il, $element, cookie; + var i, il, $element, browserData; for (i = 0, il = userInfo.length; i < il; i += 1) { $element = $formContext.find('[name=' + userInfo[i] + ']'); - cookie = $.cookie('Drupal.visitor.' + userInfo[i]); - if ($element.length && cookie) { - $element.val(cookie); + browserData = localStorage.getItem('Drupal.visitor.' + userInfo[i]); + if ($element.length && browserData) { + $element.val(browserData); + } + } + }); + $('form.user-info-from-browser').submit(function () { + var $formContext = $(this); + var i, il, $element; + for (i = 0, il = userInfo.length; i < il; i += 1) { + $element = $formContext.find('[name=' + userInfo[i] + ']'); + if ($element.length) { + localStorage.setItem('Drupal.visitor.' + userInfo[i], $element.val()); } } }); diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index a73ab15..831134d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -99,8 +99,8 @@ public function form(array $form, array &$form_state) { $is_admin = $comment->id() && $this->currentUser->hasPermission('administer comments'); if (!$this->currentUser->isAuthenticated() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) { - $form['#attached']['library'][] = 'core/jquery.cookie'; - $form['#attributes']['class'][] = 'user-info-from-cookie'; + $form['#attached']['library'][] = 'core/drupal.form'; + $form['#attributes']['class'][] = 'user-info-from-browser'; } // If not replying to a comment, use our dedicated page callback for new @@ -382,11 +382,6 @@ public function save(array $form, array &$form_state) { $uri = $entity->urlInfo(); if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) { - // Save the anonymous user information to a cookie for reuse. - if ($this->currentUser->isAnonymous()) { - user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); - } - $comment->save(); $form_state['values']['cid'] = $comment->id(); diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php index 122665f..317dc5e 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php +++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php @@ -53,8 +53,8 @@ public function form(array $form, array &$form_state) { '#required' => TRUE, ); if ($user->isAnonymous()) { - $form['#attached']['library'][] = 'core/jquery.cookie'; - $form['#attributes']['class'][] = 'user-info-from-cookie'; + $form['#attached']['library'][] = 'core/drupal.form'; + $form['#attributes']['class'][] = 'user-info-from-browser'; } // Do not allow authenticated users to alter the name or e-mail values to // prevent the impersonation of other users. @@ -150,8 +150,6 @@ public function save(array $form, array &$form_state) { // over the submitted form values. $sender->name = $message->getSenderName(); $sender->mail = $message->getSenderMail(); - // Save the anonymous user information to a cookie for reuse. - user_cookie_save(array('name' => $message->getSenderName(), 'mail' => $message->getSenderMail())); // For the e-mail message, clarify that the sender name is not verified; it // could potentially clash with a username on this site. $sender->name = t('!name (not verified)', array('!name' => $message->getSenderName())); diff --git a/core/modules/user/lib/Drupal/user/RegisterFormController.php b/core/modules/user/lib/Drupal/user/RegisterFormController.php index 30e33fe..1e9c729 100644 --- a/core/modules/user/lib/Drupal/user/RegisterFormController.php +++ b/core/modules/user/lib/Drupal/user/RegisterFormController.php @@ -44,8 +44,7 @@ public function form(array $form, array &$form_state) { return new RedirectResponse(url('user/' . \Drupal::currentUser()->id(), array('absolute' => TRUE))); } - $form['#attached']['library'][] = 'core/jquery.cookie'; - $form['#attributes']['class'][] = 'user-info-from-cookie'; + $form['#attributes']['class'][] = 'user-info-from-browser'; // Start with the default user account fields. $form = parent::form($form, $form_state, $account);