Skip to content

3.4.0

Compare
Choose a tag to compare
@dereuromark dereuromark released this 29 Feb 04:54
· 7 commits to master since this release
5e07fa7

Improvements

Added closure support for address elements in Geocoder lookup.

Sometimes, you need to have more logic for a specific address field.
In this case you can use a closure to make dynamic lookups where needed.

$this->addBehavior('Geo.Geocoder', [ 'address' => ['street', 'postal_code', 'city', function (Event $entity) {
    if ($entity->country && $entity->country->id && $entity->country_id === $entity->country->id) {
        return $entity->country->name;
    }
    if ($entity->get('country_name')) {
        return $entity->get('country_name');
    }

    if ($entity->country_id) {
        $country = $this->Countries->get($entity->country_id);
        return $country->name;
    }

    return null;
}]]);