diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php new file mode 100644 index 0000000000000000000000000000000000000000..c7725d9f05e02b6d3c7577e3df14ff262b2dcdb4 --- /dev/null +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php @@ -0,0 +1,92 @@ +<?php + +/** + * @file + * Contains \Drupal\telephone\Plugin\field\field_type\TelephoneItem. + */ + +namespace Drupal\telephone\Plugin\field\field_type; + +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; + +/** + * Plugin implementation of the 'telephone' field type. + * + * @FieldType( + * id = "telephone", + * module = "telephone", + * label = @Translation("Telephone number"), + * description = @Translation("This field stores a telephone number in the database."), + * default_widget = "telephone_default", + * default_formatter = "telephone_link" + * ) + */ +class TelephoneItem extends ConfigFieldItemBase { + + /** + * Definitions of the contained properties. + * + * @var array + */ + static $propertyDefinitions; + + /** + * {@inheritdoc} + */ + public static function schema(Field $field) { + return array( + 'columns' => array( + 'value' => array( + 'type' => 'varchar', + 'length' => 256, + 'not null' => FALSE, + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function getPropertyDefinitions() { + if (!isset(static::$propertyDefinitions)) { + static::$propertyDefinitions['value'] = array( + 'type' => 'string', + 'label' => t('Telephone number'), + ); + } + return static::$propertyDefinitions; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() { + $value = $this->get('value')->getValue(); + return $value === NULL || $value === ''; + } + + /** + * {@inheritdoc} + */ + public function getConstraints() { + $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraints = parent::getConstraints(); + + $max_length = 256; + $constraints[] = $constraint_manager->create('ComplexData', array( + 'value' => array( + 'Length' => array( + 'max' => $max_length, + 'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', array('%name' => $this->getInstance()->label, '@max' => $max_length)), + ) + ), + )); + + return $constraints; + } + +} diff --git a/core/modules/telephone/lib/Drupal/telephone/Type/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Type/TelephoneItem.php deleted file mode 100644 index 137dcbc653cd939d37186a9e4b0ae9c93fd805b6..0000000000000000000000000000000000000000 --- a/core/modules/telephone/lib/Drupal/telephone/Type/TelephoneItem.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\telephone\Type\TelephoneItem. - */ - -namespace Drupal\telephone\Type; - -use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem; - -/** - * Defines the 'telephone_field' entity field items. - */ -class TelephoneItem extends LegacyConfigFieldItem { - - /** - * Definitions of the contained properties. - * - * @see TelephoneItem::getPropertyDefinitions() - * - * @var array - */ - static $propertyDefinitions; - - /** - * Implements ComplexDataInterface::getPropertyDefinitions(). - */ - public function getPropertyDefinitions() { - if (!isset(static::$propertyDefinitions)) { - static::$propertyDefinitions['value'] = array( - 'type' => 'string', - 'label' => t('Telephone number'), - ); - } - return static::$propertyDefinitions; - } -} diff --git a/core/modules/telephone/telephone.install b/core/modules/telephone/telephone.install deleted file mode 100644 index d409b8b12b5119cac42011a37d789b6a206375bc..0000000000000000000000000000000000000000 --- a/core/modules/telephone/telephone.install +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * @file - * Install, update and uninstall functions for the Telephone module. - */ - -/** - * Implements hook_field_schema(). - */ -function telephone_field_schema($field) { - $columns = array( - 'value' => array( - 'type' => 'varchar', - 'length' => 256, - 'not null' => FALSE, - ), - ); - return array( - 'columns' => $columns, - ); -} diff --git a/core/modules/telephone/telephone.module b/core/modules/telephone/telephone.module index e6d2e7f639b4fb1cdb5487a4ecaa3c22b0c4b1bd..5445c5b12b04b4be43b0e7d631d02788409fcb5b 100644 --- a/core/modules/telephone/telephone.module +++ b/core/modules/telephone/telephone.module @@ -5,36 +5,15 @@ * Defines a simple telephone number field type. */ -/** - * Implements hook_field_info(). - */ -function telephone_field_info() { - return array( - 'telephone' => array( - 'label' => t('Telephone number'), - 'description' => t('This field stores a telephone number in the database.'), - 'default_widget' => 'telephone_default', - 'default_formatter' => 'telephone_link', - 'class' => 'Drupal\telephone\Type\TelephoneItem', - ), - ); -} - /** * Implements hook_field_info_alter(). */ function telephone_field_info_alter(&$info) { - if (module_exists('text')) { + if (Drupal::moduleHandler()->moduleExists('text')) { $info['telephone']['default_formatter'] = 'text_plain'; } } -/** - * Implements hook_field_is_empty(). - */ -function telephone_field_is_empty($item, $field_type) { - return !isset($item['value']) || $item['value'] === ''; -} /** * Implements hook_field_formatter_info_alter().