Issue #2086305 by larowlan: Add a FloatItem data type.
parent
4b72c96019
commit
bd5e04943a
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -569,12 +569,12 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
|
||||
// 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);
|
||||
|
|
Loading…
Reference in New Issue