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]);
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nedjo’s picture

Status: Active » Needs review
FileSize
7.92 KB
phayes’s picture

Just looking at the code it looks good. Still need to apply and test.

nedjo’s picture

Wrote 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:

  • FALSE: do nothing.
  • An empty array: use it to unset the existing field value.
  • A populated array: assign a new field value.

What each of these values means is not particularly intuitive. At the least, the return value should be documented in the phpdocs.

phayes’s picture

Status: Needs review » Fixed

Committed. Thanks Nedjo

nedjo’s picture

Status: Fixed » Needs review
FileSize
856 bytes

Missed a variable in the new function that was set in the original one.

phayes’s picture

Status: Needs review » Fixed

Commited.

Status: Fixed » Closed (fixed)

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