diff --git a/core/modules/email/email.module b/core/modules/email/email.module index d17e4cf..3b2fbbb 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 80603e8..64f68bd 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 @@ -9,10 +9,21 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; -use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; use Drupal\field\Plugin\Core\Entity\Field; /** + * 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 + */ +define(EMAIL_MAX_LENGTH, 254); + +/** * Plugin implementation of the 'email' field type. * * @FieldType( @@ -24,26 +35,7 @@ * default_formatter = "email_mailto" * ) */ -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 - */ - static $propertyDefinitions; +class EmailItem extends \Drupal\Core\Entity\Plugin\DataType\EmailItem { /** * {@inheritdoc} @@ -53,13 +45,7 @@ public static function schema(Field $field) { 'columns' => array( 'value' => array( 'type' => 'varchar', - // 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, + 'length' => EMAIL_MAX_LENGTH, 'not null' => FALSE, ), ), @@ -69,26 +55,6 @@ public static function schema(Field $field) { /** * {@inheritdoc} */ - public function getPropertyDefinitions() { - if (!isset(static::$propertyDefinitions)) { - static::$propertyDefinitions['value'] = array( - 'type' => 'string', - 'label' => t('E-mail address'), - ); - } - return static::$propertyDefinitions; - } - - /** - * {@inheritdoc} - */ - public function isEmpty() { - return $this->value === NULL || $this->value === ''; - } - - /** - * {@inheritdoc} - */ public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); @@ -96,8 +62,8 @@ public function getConstraints() { $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( 'Length' => array( - '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)), + 'max' => EMAIL_MAX_LENGTH, + 'maxMessage' => t('%name: the e-mail address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => EMAIL_MAX_LENGTH)), ) ), ));