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.
Problem/Motivation
Currently the geocoder widget includes fairly complex handling of field values. This handling is embedded in a hook implementation. Other modules however may have a use for geocoder's handling.
Proposed resolution
Pull the relevant code into a new function.
Remaining tasks
Needs review.
User interface changes
n/a
API changes
Introduces new function, geocoder_widget_get_field_value()
, that returns the field value for a geocoded field.
Sample code:
if ($field_value = geocoder_widget_get_field_value($entity_type, $entity, $field_instance)) {
$values = reset($field_value[LANGUAGE_NONE]);
}
Comment | File | Size | Author |
---|---|---|---|
#5 | geocoder-reuse-1627906-5.patch | 856 bytes | nedjo |
#1 | geocode-reuse-1627906-1.patch | 7.92 KB | nedjo |
Comments
Comment #1
nedjoComment #2
phayes CreditAttribution: phayes commentedJust looking at the code it looks good. Still need to apply and test.
Comment #3
nedjoWrote this because I needed it for #1627940: Add optional geocoding to map input widget.
A potentially confusing detail of the patch comes from the fact that the original function had three possible outcomes: do nothing, unset the existing field value, and assign a new field value. To handle all three, the new helper function returns one of three different values:
What each of these values means is not particularly intuitive. At the least, the return value should be documented in the phpdocs.
Comment #4
phayes CreditAttribution: phayes commentedCommitted. Thanks Nedjo
Comment #5
nedjoMissed a variable in the new function that was set in the original one.
Comment #6
phayes CreditAttribution: phayes commentedCommited.