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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Here'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.

dbolinovski’s picture

Plain formatter initial code.

dbolinovski’s picture

Plain formatter template change.

dbolinovski’s picture

Added sorting code property.

dbolinovski’s picture

Plain formatter test unit.

bojanz’s picture

Status: Active » Needs review
slasher13’s picture

some progress

bojanz’s picture

@slasher13
Please provide an interdiff, so that we know what you've changed.

slasher13’s picture

added interdiff

rocketeerbkw’s picture

FileSize
15.79 KB
2.91 KB

It 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.

  • bojanz committed 7090c97 on 8.x-1.x
    Issue #2525762 by dbolinovski, slasher13, rocketeerbkw: Create a Plain...
bojanz’s picture

Status: Needs review » Fixed

Did another iteration, committed. Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.