Skip to content

Commit

Permalink
Add min/max options to decimal fields in farm_field.factory #822
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Apr 10, 2024
1 parent bfd98ab commit ba3fda8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Issue #3390486: Add an Ontology URI field to all taxonomy terms](https://www.drupal.org/project/farm/issues/3390486)
- [Add "Days of harvest" field to Plant type terms #794](https://github.com/farmOS/farmOS/pull/794)
- [Plan record views integration #818](https://github.com/farmOS/farmOS/pull/818)
- [Add min/max options to decimal fields in farm_field.factory #822](https://github.com/farmOS/farmOS/pull/822)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions docs/development/module/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Both methods expect an array of field definition options. These include:
decimal point). Defaults to 10.
- `scale` (optional) - Number digits to the right of the decimal point.
Defaults to 2.
- `min` (optional) - The minimum value.
- `max` (optional) - The maximum value.
- `email` - Email field.
- `entity_reference` - Reference other entities. Additional options:
- `target_type` (required) - The entity type to reference (eg: `asset`,
Expand Down
8 changes: 8 additions & 0 deletions modules/core/field/src/FarmFieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ protected function modifyDecimalField(BaseFieldDefinition &$field, array $option
$field->setSetting('scale', $options['scale']);
}

// Set the min/max constraints, if specified.
if (isset($options['min'])) {
$field->setSetting('min', $options['min']);
}
if (isset($options['max'])) {
$field->setSetting('max', $options['max']);
}

// Build form and view display settings.
$field->setDisplayOptions('form', [
'type' => 'number',
Expand Down

0 comments on commit ba3fda8

Please sign in to comment.