Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GB.json #15606

Closed
wants to merge 1 commit into from
Closed

Update GB.json #15606

wants to merge 1 commit into from

Conversation

ArtDepartmentMJ
Copy link

Added Aberdeen City to the list of Cities for the Address field

Description

Related issues

Added Aberdeen City
@nfourtythree
Copy link
Contributor

Hi @ArtDepartmentMJ

Thank you for the PR!

This list of counties included in the sub-division list was obtained from a Google data source, so we hope these are correct.

The underlying library Craft uses currently doesn't have a counties list for GB and we are trying to get them to add it so we have a centralised place to update all this information. You can track the progress of that in this issue: commerceguys/addressing#111 (comment)

We will close this issue for now and suggest that you use the events built into Craft to add this county to your list if it is desperately needed. You can do that with the following code:

use CommerceGuys\Addressing\AddressFormat\AddressField;
use craft\events\DefineAddressFieldLabelEvent;
use craft\events\DefineAddressFieldsEvent;
use craft\events\DefineAddressSubdivisionsEvent;
use craft\services\Addresses;

// ...

// Add the 'administrativeArea' field to the list of fields used by the 'GB' country code
Event::on(
    Addresses::class,
    Addresses::EVENT_DEFINE_USED_FIELDS,
    function(DefineAddressFieldsEvent $event) {
        if ($event->countryCode === 'GB') {
            $event->fields[] = AddressField::ADMINISTRATIVE_AREA;
        }
    }
);

// Change the label of the 'administrativeArea' field to "County" for the 'GB' country code
Event::on(
    Addresses::class,
    Addresses::EVENT_DEFINE_FIELD_LABEL,
    function(DefineAddressFieldLabelEvent $event) {
        if ($event->countryCode === 'GB' && $event->field === AddressField::ADMINISTRATIVE_AREA) {
            $event->label = 'County';
        }
    }
);

// Add a blank option to 'GB' country code subdivisions to avoid accidental selection when resaving an address
// Add "Aberdeen City" to the list
Event::on(
    Addresses::class,
    Addresses::EVENT_DEFINE_ADDRESS_SUBDIVISIONS,
    function (DefineAddressSubdivisionsEvent $event) {
        if (!empty($event->parents) && $event->parents[0] === 'GB' && count($event->parents) === 1) {
            $event->subdivisions = array_merge(['' => 'Select county', 'Aberdeen City' => 'Aberdeen City'], $event->subdivisions);
        }
    }
);

Hope this helps, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants