diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index 4b40668..e38fbed 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -36,13 +36,14 @@ * @return array * An associative array with the following key/value pairs: * - columns: An array of Schema API column specifications, keyed by column - * name. This specifies what comprises a value for a given field. For - * example, a value for a number field is simply 'value', while a value - * for a formatted text field is the combination of 'value' and 'format'. - * It is recommended to avoid having the column definitions depend on - * field settings when possible. No assumptions should be made on how - * storage engines internally use the original column name to structure - * their storage. + * name. The columns need to be a subset of the properties defined in + * getPropertyDefinitions(). This specifies what comprises a value for a + * given field. For example, a value for a number field is simply 'value', + * while a value for a formatted text field is the combination of 'value' + * and 'format'. It is recommended to avoid having the column definitions + * depend on field settings when possible. No assumptions should be made + * on how storage engines internally use the original column name to + * structure their storage. * - indexes: (optional) An array of Schema API index definitions. Only * columns that appear in the 'columns' array are allowed. Those indexes * will be used as default indexes. Callers of field_create_field() can diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 883faae..1bb6780 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\Cache; +use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem; use Drupal\Core\Language\Language; use Drupal\Core\Utility\ModuleInfo; use Drupal\user\UserInterface; @@ -343,7 +344,7 @@ function system_element_info() { '#input' => TRUE, '#size' => 60, // user.module is not loaded in case of early bootstrap errors. - '#maxlength' => defined('EMAIL_MAX_LENGTH') ? EMAIL_MAX_LENGTH : 255, + '#maxlength' => EmailItem::EMAIL_MAX_LENGTH, '#autocomplete_route_name' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_email'), diff --git a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php index 2399a58..a547c02 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php @@ -7,6 +7,7 @@ namespace Drupal\user\Form; +use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem; use Drupal\Core\Form\FormBase; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; @@ -74,7 +75,7 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'textfield', '#title' => $this->t('Username or e-mail address'), '#size' => 60, - '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH), + '#maxlength' => max(USERNAME_MAX_LENGTH, EmailItem::EMAIL_MAX_LENGTH), '#required' => TRUE, '#attributes' => array( 'autocorrect' => 'off', diff --git a/core/modules/user/lib/Drupal/user/Tests/UserValidationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserValidationTest.php index 99aaecb..9725c1f 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserValidationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserValidationTest.php @@ -8,6 +8,7 @@ namespace Drupal\user\Tests; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem; use Drupal\simpletest\DrupalUnitTestBase; /** @@ -106,12 +107,12 @@ function testValidation() { $this->assertEqual($violations[0]->getPropertyPath(), 'mail.0.value'); $this->assertEqual($violations[0]->getMessage(), t('This value is not a valid email address.')); - $mail = $this->randomName(EMAIL_MAX_LENGTH - 11) . '@example.com'; + $mail = $this->randomName(EmailItem::EMAIL_MAX_LENGTH - 11) . '@example.com'; $user->set('mail', $mail); $violations = $user->validate(); - $this->assertEqual(count($violations), 1, 'Violation found when email is too long'); + $this->assertEqual(count($violations), 2, 'Violation found when email is too long'); $this->assertEqual($violations[0]->getPropertyPath(), 'mail.0.value'); - $this->assertEqual($violations[0]->getMessage(), t('This value is not a valid email address.')); + $this->assertEqual($violations[0]->getMessage(), t('%name: the e-mail address can not be longer than @max characters.', array('%name' => $user->get('mail')->getFieldDefinition()->getFieldLabel(), '@max' => EmailItem::EMAIL_MAX_LENGTH))); // Provoke a e-mail collision with an exsiting user. $user->set('mail', 'existing@exmaple.com'); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 5751f02..eb417af 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -24,11 +24,6 @@ const USERNAME_MAX_LENGTH = 60; /** - * Maximum length of user e-mail text field. - */ -const EMAIL_MAX_LENGTH = 255; - -/** * Only administrators can create user accounts. */ const USER_REGISTER_ADMINISTRATORS_ONLY = 'admin_only';