diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php index 226e27c..5b9173b 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\Component\Utility\MapArray; /** * Plugin implementation of the 'number_decimal' field type. @@ -39,7 +40,6 @@ class DecimalItem extends NumberItemBase { * {@inheritdoc} */ public function getPropertyDefinitions() { - if (!isset(static::$propertyDefinitions)) { static::$propertyDefinitions['value'] = array( 'type' => 'string', @@ -71,22 +71,23 @@ public static function schema(Field $field) { public function settingsForm(array $form, array &$form_state) { $element = array(); $field = $this->getInstance()->getField(); + $has_data = $field->hasData(); $element['precision'] = array( '#type' => 'select', '#title' => t('Precision'), - '#options' => drupal_map_assoc(range(10, 32)), + '#options' => MapArray::copyValuesToKeys(range(10, 32)), '#default_value' => $field->settings['precision'], '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), - '#disabled' => $field->hasData(), + '#disabled' => $has_data, ); $element['scale'] = array( '#type' => 'select', '#title' => t('Scale'), - '#options' => drupal_map_assoc(range(0, 10)), + '#options' => MapArray::copyValuesToKeys(range(0, 10)), '#default_value' => $field->settings['scale'], '#description' => t('The number of digits to the right of the decimal.'), - '#disabled' => $field->hasData(), + '#disabled' => $has_data, ); return $element; @@ -96,7 +97,10 @@ public function settingsForm(array $form, array &$form_state) { * {@inheritdoc} */ public function preSave() { - $this->getInstance()->getField()->setValue(round($this->getInstance()->getField()->getValue(), $this->getInstance()->getField()->settings['scale'])); + $this->setValue( + round($this->get('value')->getValue(), + $this->getInstance()->getField()->settings['scale']) + ); } } diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/FloatItem.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/FloatItem.php index 9ca5c56..0cd5e6e 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/FloatItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/FloatItem.php @@ -35,7 +35,6 @@ class FloatItem extends NumberItemBase { * {@inheritdoc} */ public function getPropertyDefinitions() { - if (!isset(static::$propertyDefinitions)) { static::$propertyDefinitions['value'] = array( 'type' => 'float', diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/IntegerItem.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/IntegerItem.php index ebca4aa..29f0e34 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/IntegerItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/IntegerItem.php @@ -35,7 +35,6 @@ class IntegerItem extends NumberItemBase { * {@inheritdoc} */ public function getPropertyDefinitions() { - if (!isset(static::$propertyDefinitions)) { static::$propertyDefinitions['value'] = array( 'type' => 'integer', diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php index f746ba4..3015c4b 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php @@ -8,7 +8,6 @@ namespace Drupal\number\Plugin\field\field_type; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; -use Drupal\Core\Entity\Field\PrepareCacheInterface; /** * Base class for 'number' configurable field types. @@ -78,26 +77,28 @@ public function isEmpty() { public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); + $settings = $this->getInstance()->settings; + $label = $this->getInstance()->label; - if (!empty($this->getInstance()->getField()->settings['min'])) { - $min = $this->getInstance()->getField()->settings['min']; + if (!empty($settings['min'])) { + $min = $settings['min']; $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( - 'Length' => array( + 'Range' => array( 'min' => $min, - 'minMessage' => t('%name: the value may be no less than %min.', array('%name' => $this->getInstance()->label, '%min' => $min)), + 'minMessage' => t('%name: the value may be no less than %min.', array('%name' => $label, '%min' => $min)), ) ), )); } - if (!empty($this->getInstance()->getField()->settings['max'])) { - $max = $this->getInstance()->getField()->settings['max']; + if (!empty($settings['max'])) { + $max = $settings['max']; $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( - 'Length' => array( + 'Range' => array( 'max' => $max, - 'minMessage' => t('%name: the value may be no greater than %max.', array('%name' => $this->getInstance()->label, '%max' => $max)), + 'maxMessage' => t('%name: the value may be no greater than %max.', array('%name' => $label, '%max' => $max)), ) ), ));