Skip to content
Snippets Groups Projects
Commit bd5e0494 authored by Alex Pott's avatar Alex Pott
Browse files

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

parent 4b72c960
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment