In commerce_price we created two price formatters:
- Default (uses the number format rules to output a formatted price)
- Plain (uses a twig template and lets the themer choose their own output)
In address we also have a default formatter which formats based on the address format. However, we don't have a Plain formatter yet, though it makes a lot of sense to have it.
It would allow people maximum control over the outputted address, and would allow people to format all addresses, regardless of the country, the same way.
There's already a matching D7 feature request with a patch: #1541384: Provide regular theme function for displaying an address as an alternative to formatter plugins.
The default theme function should output the following format:
recipient
organization
address_line1
address_line2
dependent_locality.code
locality.code postal_code administrative_area.code
country.name
The subdivisions and country should have both the code and the name properties available.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff.txt | 2.91 KB | rocketeerbkw |
#10 | create_a_plain_formatter-2525762-10.patch | 15.79 KB | rocketeerbkw |
Comments
Comment #1
bojanz CreditAttribution: bojanz at Centarro commentedHere's the price plain formatter to use as a reference: https://github.com/commerceguys/commerce/blob/8.x-2.x/modules/price/src/...
And the matching twig template: https://github.com/commerceguys/commerce/blob/8.x-2.x/modules/price/temp...
We should also write a test that confirms that the render array returned by the formatter has the expected data.
Comment #2
dbolinovski CreditAttribution: dbolinovski commentedPlain formatter initial code.
Comment #3
dbolinovski CreditAttribution: dbolinovski commentedPlain formatter template change.
Comment #4
dbolinovski CreditAttribution: dbolinovski commentedAdded sorting code property.
Comment #5
dbolinovski CreditAttribution: dbolinovski commentedPlain formatter test unit.
Comment #6
bojanz CreditAttribution: bojanz at Centarro commentedComment #7
slasher13some progress
Comment #8
bojanz CreditAttribution: bojanz at Centarro commented@slasher13
Please provide an interdiff, so that we know what you've changed.
Comment #9
slasher13added interdiff
Comment #10
rocketeerbkw CreditAttribution: rocketeerbkw commentedIt seems subdivisions aren't always guaranteed to be a code/name pair. A US address, for example, gives the locality (city) as a string and trying to access code/name returns null. I changed the template to output either the code/name if it's available or just the string. This gives me the address outputs I want.
I also fixed the tests which weren't passing anyway.
And there's a small documentation fix.
Comment #12
bojanz CreditAttribution: bojanz at Centarro commentedDid another iteration, committed. Thank you!