diff --git a/core/lib/Drupal/Core/Entity/Plugin/field/field_type/EmailItem.php b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/EmailItem.php index 190a36e..e1b70b6 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/field/field_type/EmailItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/EmailItem.php @@ -7,7 +7,8 @@ namespace Drupal\Core\Entity\Plugin\field\field_type; -use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem; +use Drupal\field\FieldInterface; +use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; /** * Defines the 'email' entity field type. @@ -15,11 +16,10 @@ * @FieldType( * id = "email", * label = @Translation("E-mail"), - * description = @Translation("An entity field containing an e-mail value."), - * configurable = false + * description = @Translation("An entity field containing an e-mail value.") * ) */ -class EmailItem extends LegacyConfigFieldItem { +class EmailItem extends ConfigFieldItemBase { /** * Definitions of the contained properties. @@ -51,4 +51,51 @@ public function getPropertyDefinitions() { public function isEmpty() { return $this->value === NULL || $this->value === ''; } + + /** + * 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 + */ + const EMAIL_MAX_LENGTH = 254; + + /** + * {@inheritdoc} + */ + public static function schema(FieldInterface $field) { + return array( + 'columns' => array( + 'value' => array( + 'type' => 'varchar', + 'length' => static::EMAIL_MAX_LENGTH, + 'not null' => FALSE, + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function getConstraints() { + $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraints = parent::getConstraints(); + + $constraints[] = $constraint_manager->create('ComplexData', array( + 'value' => array( + 'Length' => array( + 'max' => static::EMAIL_MAX_LENGTH, + 'maxMessage' => t('%name: the e-mail address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => static::EMAIL_MAX_LENGTH)), + ) + ), + )); + + return $constraints; + } + } diff --git a/core/modules/email/email.module b/core/modules/email/email.module index 5a5f116..d77df82 100644 --- a/core/modules/email/email.module +++ b/core/modules/email/email.module @@ -31,9 +31,13 @@ function email_help($path, $arg) { * Implements hook_field_info_alter(). */ function email_field_info_alter(&$info) { + $info['email']['default_widget'] = 'email_default'; if (\Drupal::moduleHandler()->moduleExists('text')) { $info['email']['default_formatter'] = 'text_plain'; } + else { + $info['email']['default_formatter'] = 'email_mailto'; + } } /** diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php b/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php deleted file mode 100644 index d34a559..0000000 --- a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php +++ /dev/null @@ -1,74 +0,0 @@ - array( - 'value' => array( - 'type' => 'varchar', - 'length' => static::EMAIL_MAX_LENGTH, - 'not null' => FALSE, - ), - ), - ); - } - - /** - * {@inheritdoc} - */ - public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); - $constraints = parent::getConstraints(); - - $constraints[] = $constraint_manager->create('ComplexData', array( - 'value' => array( - 'Length' => array( - 'max' => static::EMAIL_MAX_LENGTH, - 'maxMessage' => t('%name: the e-mail address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => static::EMAIL_MAX_LENGTH)), - ) - ), - )); - - return $constraints; - } - -}