Commit bd5e0494 authored by alexpott's avatar alexpott

Issue #2086305 by larowlan: Add a FloatItem data type.

parent 4b72c960
<?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;
}
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment