Hi. I already have like 300 nodes with select list field that contains like 5 different keys and each node has one of them selected. I decided I need to add this Other feature, but it doesn't really work, because no matter what I enter to Other field it gives illegal value. Probably because of keys in the Allowed list. But again, I cannot remove keys from Allowed list, because it gives me message that they are in use. So I'm basically stuck.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mradcliffe’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

Yes, you are kind of stuck. The only thing I can think of is to modify the field_config table entry for the field manually to get rid of that. However that's not a simple task as it requires unserializing and reserializing from PHP.

Something like this:

  $serialized = db_select('field_config')->condition('field_name', 'field_my_field_name')->fields('field_config', array('data'))->execute()->fetchField();

  $data = unserialize($serialized);
  $data['settings']['allowed_values'] = array();
  db_update('field_config')->condition('field_name', 'field_my_field_name')->fields(array('data' => serialize($data)))->execute();

Might be a feature in this: to remove old allowed values.

jenlampton’s picture

Category: Support request » Bug report

I'm running into the same problem as mentioned above. If we could set the "Select list options" to be the same as the "Allowed values" that might help. I noticed that after adding this widget to an existing field, the "Select list options" were set to only other|Other. Once those were updated I was able to save items with no trouble.

mradcliffe’s picture

I think that this would be doable by writing a custom migration (not a Migrate migration). I think a form that lists possible fields using widget, and then on submit, get the raw field settings, unserialize, change, and use drupal_write_record. Then add the options to the field widget and save that via the API.

This is a test only patch, which should hopefully fail in the right ways.

Status: Needs review » Needs work