Skip to content

Ensure custom address fields are available in templates#118

Merged
duncanmcclean merged 3 commits into1.xfrom
custom-address-fields
Jan 22, 2026
Merged

Ensure custom address fields are available in templates#118
duncanmcclean merged 3 commits into1.xfrom
custom-address-fields

Conversation

@duncanmcclean
Copy link
Owner

@duncanmcclean duncanmcclean commented Jan 21, 2026

This pull request ensures that custom address fields added via the fields hook are available in templates.

They aren't currently because the Address object is passed to the fieldtype's augment method, which ultimately calls ->toArray() on the address, which returns a fixed array of fields.

To address this (see what I did there?), I've refactored the Address object to accept an array, rather than arguments for each "part" of an address.

I've also moved the address fields out of the fieldtype and into the main Address object.

Related: #111

Address::hook('fields')

Technically, there shouldn't be any breaking changes in a beta. However... I only released this feature a few days ago and I'm pretty sure there's only 1 person using it, so I'm gonna break something and hope no one tells me off. 🙈

You'll need to change which Address class you're importing:

- use DuncanMcClean\Cargo\Fieldtypes\Address;
+ use DuncanMcClean\Cargo\Data\Address;

You'll also need to make sure you return the field handle as a key, rather than a nested array with handle/field keys:

'firstname' => [
    'type' => 'text',
    'display' => __('Firstname'),
    'listable' => false,
    'width' => 50,
],

@duncanmcclean duncanmcclean changed the title Ensure custom address fields are available in templates Make custom address fields are available in templates Jan 22, 2026
@duncanmcclean duncanmcclean changed the title Make custom address fields are available in templates Ensure custom address fields are available in templates Jan 22, 2026
@duncanmcclean duncanmcclean marked this pull request as ready for review January 22, 2026 01:27
@duncanmcclean duncanmcclean merged commit cc0c5b1 into 1.x Jan 22, 2026
8 checks passed
@duncanmcclean duncanmcclean deleted the custom-address-fields branch January 22, 2026 01:27
@github-actions
Copy link

Released as part of v1.0.0-beta.2.

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.

1 participant