diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-07-06 14:02:58 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-07-06 14:02:58 -0700 |
commit | 1f00fb6cc7595b05cfd7c138d0ef490de7da91f8 (patch) | |
tree | 0a3ea3674110e1a81e705e2c6b0725392dfb1454 /modules | |
parent | d732bf85d9e6de9a1626c8849729fd71378c6c1b (diff) | |
download | brdo-1f00fb6cc7595b05cfd7c138d0ef490de7da91f8.tar.gz brdo-1f00fb6cc7595b05cfd7c138d0ef490de7da91f8.tar.bz2 |
Issue #1047070 by douggreen, marcingy, yched: Fixed list_field_update_forbid() logic is backwards.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/field/modules/list/list.module | 2 | ||||
-rw-r--r-- | modules/field/modules/list/tests/list.test | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/modules/field/modules/list/list.module b/modules/field/modules/list/list.module index 608679bbb..2518ebcfc 100644 --- a/modules/field/modules/list/list.module +++ b/modules/field/modules/list/list.module @@ -343,7 +343,7 @@ function list_allowed_values_string($values) { function list_field_update_forbid($field, $prior_field, $has_data) { if ($field['module'] == 'list' && $has_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)) { throw new FieldUpdateForbiddenException(t('Cannot update a list field to not include keys with existing data.')); } diff --git a/modules/field/modules/list/tests/list.test b/modules/field/modules/list/tests/list.test index 941d2b4cb..dec09560f 100644 --- a/modules/field/modules/list/tests/list.test +++ b/modules/field/modules/list/tests/list.test @@ -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][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. $this->field['settings']['allowed_values'] = array(2 => 'Two'); field_update_field($this->field); |