Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In various locations, the array returned by field_get_items() is accessed directly by $item['value'], which is not always correct. The countries module, for example, keeps its value in $item['iso2']. field_view_value() should be used to get the value, instead.
Comment | File | Size | Author |
---|---|---|---|
#8 | simple_ldap-1972150-8.patch | 29.69 KB | q0rban |
#6 | simple_ldap-1972150-6.patch | 18.47 KB | q0rban |
Comments
Comment #1
blc CreditAttribution: blc commentedUsing field_view_value() did not work so well, and it's probably best not to try to use a renderable array anyway.
One thought is to include it in the attribute map. Something like 'drupal' => '#field_country[iso2]'. I'm not sure how the "iso2" value would be discoverable by end users, though.
Comment #2
q0rban CreditAttribution: q0rban commentedI don't think we want field_view_value() here. There is the case where you want the raw value stored in the column, not the display value. The real problem is that the column names don't match, as described in #1995602: Allow mapping of fields with columns other than value.
Comment #3
blc CreditAttribution: blc commentedComment #4
q0rban CreditAttribution: q0rban commentedOne possibility is to have the field mapping array optionally contain the column names in them.
For instance:
[value] would be implied, so this would also work:
Comment #5
blc CreditAttribution: blc commentedI was hoping to avoid explicitly specifying the field column in the config, since that is a little difficult to find. But, after digging into field API more, I think this might be the only reasonable option.
Comment #6
q0rban CreditAttribution: q0rban commentedOk, here is a patch that moves the mapping into it's own class.
@blc, a few things to note:
Comment #7
q0rban CreditAttribution: q0rban commentedAlso, I would carefully review this patch, as it looked like a few other commits went in while I was working on this, so I want to make sure I didn't break anything you did before.
Comment #8
q0rban CreditAttribution: q0rban commentedWhoops, I forgot to git add the SimpleLdapUserMap class. Also, I've added some documentation and strictly declared some arguments since I last tested this, so I may have broken something in that process. Let me know if so, and I will re-roll.
Comment #9
blc CreditAttribution: blc commentedCommitted, thanks!