Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3421017
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
drupal-3421017
Commits
f6497d73
Commit
f6497d73
authored
13 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1047070
by douggreen, marcingy, yched: Fixed list_field_update_forbid() logic is backwards.
parent
e4c20675
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/field/modules/list/list.module
+1
-1
1 addition, 1 deletion
modules/field/modules/list/list.module
modules/field/modules/list/tests/list.test
+17
-0
17 additions, 0 deletions
modules/field/modules/list/tests/list.test
with
18 additions
and
1 deletion
modules/field/modules/list/list.module
+
1
−
1
View file @
f6497d73
...
@@ -343,7 +343,7 @@ function list_allowed_values_string($values) {
...
@@ -343,7 +343,7 @@ function list_allowed_values_string($values) {
function
list_field_update_forbid
(
$field
,
$prior_field
,
$has_data
)
{
function
list_field_update_forbid
(
$field
,
$prior_field
,
$has_data
)
{
if
(
$field
[
'module'
]
==
'list'
&&
$has_data
)
{
if
(
$field
[
'module'
]
==
'list'
&&
$has_data
)
{
// Forbid any update that removes allowed values with actual data.
// Forbid any update that removes allowed values with actual data.
$lost_keys
=
array_diff
(
array_keys
(
$field
[
'settings'
][
'allowed_values'
]),
array_keys
(
$
prior_
field
[
'settings'
][
'allowed_values'
]));
$lost_keys
=
array_diff
(
array_keys
(
$
prior_
field
[
'settings'
][
'allowed_values'
]),
array_keys
(
$field
[
'settings'
][
'allowed_values'
]));
if
(
_list_values_in_use
(
$field
,
$lost_keys
))
{
if
(
_list_values_in_use
(
$field
,
$lost_keys
))
{
throw
new
FieldUpdateForbiddenException
(
t
(
'Cannot update a list field to not include keys with existing data.'
));
throw
new
FieldUpdateForbiddenException
(
t
(
'Cannot update a list field to not include keys with existing data.'
));
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/field/modules/list/tests/list.test
+
17
−
0
View file @
f6497d73
...
@@ -55,6 +55,23 @@ class ListFieldTestCase extends FieldTestCase {
...
@@ -55,6 +55,23 @@ class ListFieldTestCase extends FieldTestCase {
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
field_name
][
$langcode
][
2
]),
t
(
'Option 2 exists'
));
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
field_name
][
$langcode
][
2
]),
t
(
'Option 2 exists'
));
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
field_name
][
$langcode
][
3
]),
t
(
'Option 3 exists'
));
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
field_name
][
$langcode
][
3
]),
t
(
'Option 3 exists'
));
// Use one of the values in an actual entity, and check that this value
// cannot be removed from the list.
$entity
=
field_test_create_stub_entity
();
$entity
->
{
$this
->
field_name
}[
$langcode
][
0
]
=
array
(
'value'
=>
1
);
field_test_entity_save
(
$entity
);
$this
->
field
[
'settings'
][
'allowed_values'
]
=
array
(
2
=>
'Two'
);
try
{
field_update_field
(
$this
->
field
);
$this
->
fail
(
t
(
'Cannot update a list field to not include keys with existing data.'
));
}
catch
(
FieldException
$e
)
{
$this
->
pass
(
t
(
'Cannot update a list field to not include keys with existing data.'
));
}
// Empty the value, so that we can actually remove the option.
$entity
->
{
$this
->
field_name
}[
$langcode
]
=
array
();
field_test_entity_save
(
$entity
);
// Removed options do not appear.
// Removed options do not appear.
$this
->
field
[
'settings'
][
'allowed_values'
]
=
array
(
2
=>
'Two'
);
$this
->
field
[
'settings'
][
'allowed_values'
]
=
array
(
2
=>
'Two'
);
field_update_field
(
$this
->
field
);
field_update_field
(
$this
->
field
);
...
...
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