In select_or_other_field_widget_form_prepare_options(),
keys from php options are being replaced with values... e.g.

array(123 => 'Name')

becomes

array('Name' => 'Name')

Attached is a patch to preserve the keys.

Comments

danielb’s picture

Status: Active » Fixed

Makes sense to me, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

puddyglum’s picture

Status: Needs review » Active

(Skip this, see comment #5)

This created a problem for us in 7.x-2.8 because the values being stored in the field table used to be literal, but now they are numerical keys. Used to be "Orange", "Green", etc., and now are 0, 1, 2, etc.

When the Node is loaded for view the real value of the field isn't available, all we get is the numerical key value.

Is there a way to make both of them work? For now we've just removed this patch from 7.x-2.8 and everything else works fine.

puddyglum’s picture

Status: Active » Closed (fixed)

(Skip this, see comment #5)

Nevermind, we just need to update all of our Select (or Other) fields to have Keys. In Drupal Select fields of type Text, it will automatically add the Key if you don't specify it.

What you enter into a Drupal Select widget "Allowed values list":
Option 1
After saving field:
Option 1|Option 1

I believe this module needs that now, otherwise new entries will get numerical keys by default, which could change overtime if you add/re-arrange the options. For instance, you add or re-order the fields, and suddenly a field with value 1 now displays something else.

A sample before and after (if you don't manually set keys) looks like:

entity_type bundle     deleted entity_id revision_id language delta field_foo_value field_foo_format
node        foo_record 0       136511    136669      und      0     Option 1        NULL
node        foo_record 0       136512    136670      und      0     0               NULL
puddyglum’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.06 KB

Actually, the problem is that this fix simply assumed that if no key was specified, then it must be PHP. I've added a fix which checks for the possibility of no specified key, and no PHP. Tested and it works.

danielb’s picture

Status: Closed (fixed) » Fixed

commited

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nicholas.alipaz’s picture

  • Commit 937a874 on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1356112 by rellis: Preserve available options php keys.
    
    
  • Commit 6e85a56 on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1356112 by jmonkfish: Update to preserving available options keys...