Skip to content

Is it possible for a plugin to use the Address Field like Commerce v4 does in Store Settings? #11173

Answered by BenParizek
BenParizek asked this question in Q&A
Discussion options

You must be logged in to vote

After a bit more digging, this appears possible.


I can create the field like so, passing it an address Element:

$locationField = Cp::addressCardsHtml(
  addresses: [$addressElement],
  config: [
      'name' => 'locationAddressId',
      'maxAddresses' => 1,
  ]
);

Return the code generated for the addressCardsHtml to the template and output it with the |raw filter:

{{ locationField|raw }}

And add an input to identify the address field I'm managing within the form the address exists:

{{ hiddenInput('locationAddressId', 7) }}


To address the permission issues on save, you will need to add support for the Address::EVENT_AUTHORIZE_VIEW and Address::EVENT_AUTHORIZE_SAVE events. See the exa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@brandonkelly
Comment options

Answer selected by BenParizek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants