Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
884ec874
Commit
884ec874
authored
10 months ago
by
Joshua Sedler
Browse files
Options
Downloads
Patches
Plain Diff
Fix typo in update hook, cast string values and adjust "scale" max value
parent
51341d63
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!8282
Issue #2230909: Simple decimals fail to pass validation
,
!579
Issue #2230909: Simple decimals fail to pass validation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php
+2
-2
2 additions, 2 deletions
.../Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php
core/modules/field/field.install
+7
-11
7 additions, 11 deletions
core/modules/field/field.install
with
9 additions
and
13 deletions
core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php
+
2
−
2
View file @
884ec874
...
@@ -74,7 +74,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
...
@@ -74,7 +74,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
'#type'
=>
'number'
,
'#type'
=>
'number'
,
'#title'
=>
$this
->
t
(
'Precision'
),
'#title'
=>
$this
->
t
(
'Precision'
),
'#min'
=>
10
,
'#min'
=>
10
,
'#max'
=>
ini_get
(
'precision'
)
<=
10
?
10
:
ini_get
(
'precision'
),
'#max'
=>
max
((
int
)
ini_get
(
'precision'
),
10
),
'#default_value'
=>
$settings
[
'precision'
],
'#default_value'
=>
$settings
[
'precision'
],
'#description'
=>
$this
->
t
(
'The total number of digits to store in the database, including those to the right of the decimal.'
),
'#description'
=>
$this
->
t
(
'The total number of digits to store in the database, including those to the right of the decimal.'
),
'#disabled'
=>
$has_data
,
'#disabled'
=>
$has_data
,
...
@@ -84,7 +84,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
...
@@ -84,7 +84,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
'#type'
=>
'number'
,
'#type'
=>
'number'
,
'#title'
=>
$this
->
t
(
'Scale'
,
[],
[
'context'
=>
'decimal places'
]),
'#title'
=>
$this
->
t
(
'Scale'
,
[],
[
'context'
=>
'decimal places'
]),
'#min'
=>
0
,
'#min'
=>
0
,
'#max'
=>
ini_get
(
'precision'
),
'#max'
=>
max
((
int
)
ini_get
(
'precision'
),
10
),
'#default_value'
=>
$settings
[
'scale'
],
'#default_value'
=>
$settings
[
'scale'
],
'#description'
=>
$this
->
t
(
'The number of digits to the right of the decimal.'
),
'#description'
=>
$this
->
t
(
'The number of digits to the right of the decimal.'
),
'#disabled'
=>
$has_data
,
'#disabled'
=>
$has_data
,
...
...
This diff is collapsed.
Click to expand it.
core/modules/field/field.install
+
7
−
11
View file @
884ec874
...
@@ -25,25 +25,21 @@ function field_update_10001() {
...
@@ -25,25 +25,21 @@ function field_update_10001() {
foreach
(
$decimalFieldStorageEntities
as
$decimalFieldStorageEntity
)
{
foreach
(
$decimalFieldStorageEntities
as
$decimalFieldStorageEntity
)
{
/** @var \Drupal\field\Entity\FieldStorageConfig $decimalFieldStorageEntity*/
/** @var \Drupal\field\Entity\FieldStorageConfig $decimalFieldStorageEntity*/
$castedInitialPrecisionValue
=
(
int
)
$decimalFieldStorageEntity
->
getSetting
(
'precision'
);
$precision
=
(
int
)
ini_get
(
'precision'
);
$precisionMax
=
max
(
$precision
,
10
);
// Adjust the precision value, if it is higher, than the allowed
// Adjust the precision value, if it is higher, than the allowed
// initial precision configuration option value:
// initial precision configuration option value:
$precisionValue
=
$decimalFieldStorageEntity
->
getSetting
(
'precision'
);
$precisionValue
=
(
int
)
$decimalFieldStorageEntity
->
getSetting
(
'precision'
);
$newPrecisionMaxValue
=
$castedInitialPrecisionValue
<=
10
?
10
:
$castedInitialPrecisionValue
;
$newPrecisionValue
=
$precisionValue
>
$precisionMax
?
$precisionMax
:
$precisionValue
;
// Set the new precision value:
$newPrecisionValue
=
$precisionValue
>
$newPrecisionMaxValue
?
$newPrecisionMaxValue
:
$precisionValue
;
// Adjust the scale value, if it is higher, than the allowed
// Adjust the scale value, if it is higher, than the allowed
// initial precision configuration option value:
// initial precision configuration option value:
$scaleValue
=
$decimalFieldStorageEntity
->
getSetting
(
'scale'
);
$scaleValue
=
(
int
)
$decimalFieldStorageEntity
->
getSetting
(
'scale'
);
$newScaleValue
=
$scaleValue
>
$precisionMax
?
$precisionMax
:
$scaleValue
;
// Set the new scale value:
$newScaleValue
=
$scaleValue
>
$castedInitialPrecisionValue
?
$castedInitialPrecisionValue
:
$scaleValue
;
// Set the new precision and scale values if they changed:
// Set the new precision and scale values if they changed:
if
(
$precisionValue
!=
$newPrecisionValue
||
$scaleValue
!=
$newScaleValue
)
{
if
(
$precisionValue
!=
=
$newPrecisionValue
||
$scaleValue
!=
=
$newScaleValue
)
{
$decimalFieldStorageEntity
->
setSetting
(
'precision'
,
$newPrecisionValue
);
$decimalFieldStorageEntity
->
setSetting
(
'precision'
,
$newPrecisionValue
);
$decimalFieldStorageEntity
->
setSetting
(
'scale'
,
$newScaleValue
);
$decimalFieldStorageEntity
->
setSetting
(
'scale'
,
$newScaleValue
);
$decimalFieldStorageEntity
->
save
();
$decimalFieldStorageEntity
->
save
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment