diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/FloatItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/FloatItem.php new file mode 100644 index 0000000000000000000000000000000000000000..5cd50f9a7c33629e7325bab052630600daf6b50c --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/FloatItem.php @@ -0,0 +1,48 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Entity\Plugin\DataType\FloatItem. + */ + +namespace Drupal\Core\Entity\Plugin\DataType; + +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; +use Drupal\Core\Entity\Field\FieldItemBase; + +/** + * Defines the 'float_field' entity field item. + * + * @DataType( + * id = "float_field", + * label = @Translation("Float field item"), + * description = @Translation("An entity field containing an float value."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) + */ +class FloatItem extends FieldItemBase { + + /** + * Definitions of the contained properties. + * + * @see IntegerItem::getPropertyDefinitions() + * + * @var array + */ + static $propertyDefinitions; + + /** + * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). + */ + public function getPropertyDefinitions() { + + if (!isset(static::$propertyDefinitions)) { + static::$propertyDefinitions['value'] = array( + 'type' => 'float', + 'label' => t('Float value'), + ); + } + return static::$propertyDefinitions; + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php index 6415f27a15b2aaecc447cd5946a951b8fb7195be..d0d61fa1f1d0b9b56b3b717278b4c19bbfdc9836 100644 --- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php @@ -569,12 +569,12 @@ public function testTypedDataValidation() { // Test the Null constraint with typed data containers. $definition = array( - 'type' => 'integer_field', + 'type' => 'float_field', 'constraints' => array( 'Null' => array(), ), ); - $field_item = $this->typedData->create($definition, array('value' => 10)); + $field_item = $this->typedData->create($definition, array('value' => 11.5)); $violations = $field_item->validate(); $this->assertEqual($violations->count(), 1); $field_item = $this->typedData->create($definition);