diff --git a/core/modules/email/email.module b/core/modules/email/email.module index 3b2fbbb..d17e4cf 100644 --- a/core/modules/email/email.module +++ b/core/modules/email/email.module @@ -22,7 +22,7 @@ function email_help($path, $arg) { * Implements hook_field_info_alter(). */ function email_field_info_alter(&$info) { - if (Drupal::moduleHandler()->moduleExists('text')) { + if (\Drupal::moduleHandler()->moduleExists('text')) { $info['email']['default_formatter'] = 'text_plain'; } } diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/EmailItem.php b/core/modules/email/lib/Drupal/email/Plugin/field/field_type/EmailItem.php index 3530f34..80603e8 100644 --- a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/EmailItem.php +++ b/core/modules/email/lib/Drupal/email/Plugin/field/field_type/EmailItem.php @@ -27,6 +27,18 @@ class EmailItem extends ConfigFieldItemBase { /** + * Defines the max length for an email address + * + * The maximum length of an e-mail address is 254 characters. RFC 3696 + * specifies a total length of 320 characters, but mentions that + * addresses longer than 256 characters are not normally useful. Erratum + * 1690 was then released which corrected this value to 254 characters. + * @see http://tools.ietf.org/html/rfc3696#section-3 + * @see http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 + */ + protected static $emailMaxLength = 254; + + /** * Definitions of the contained properties. * * @var array @@ -41,7 +53,13 @@ public static function schema(Field $field) { 'columns' => array( 'value' => array( 'type' => 'varchar', - 'length' => 254, + // The maximum length of an e-mail address is 254 characters. RFC 3696 + // specifies a total length of 320 characters, but mentions that + // addresses longer than 256 characters are not normally useful. Erratum + // 1690 was then released which corrected this value to 254 characters. + // @see http://tools.ietf.org/html/rfc3696#section-3 + // @see http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 + 'length' => self::$emailMaxLength, 'not null' => FALSE, ), ), @@ -65,8 +83,7 @@ public function getPropertyDefinitions() { * {@inheritdoc} */ public function isEmpty() { - $value = $this->get('value')->getValue(); - return $value === NULL || $value === ''; + return $this->value === NULL || $this->value === ''; } /** @@ -76,12 +93,11 @@ public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - $max_length = 254; $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( 'Length' => array( - 'max' => $max_length, - 'maxMessage' => t('%name: the e-mail address may not be longer than @max characters.', array('%name' => $this->getInstance()->label, '@max' => $max_length)), + 'max' => self::$emailMaxLength, + 'maxMessage' => t('%name: the e-mail address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => self::$emailMaxLength)), ) ), ));