The default and plain formatters are very nice, but requires some tinkering to get them to produce a nice output.

The default renderer wraps each address line nicely in it's own span with a class, making it easy to target and style. Yet it adds forced line-breaks (<br/>) after each line, even if that line is empty.if that line is empty.

The plain formatter outputs it all as plain text, where each address line is not wrapped. This can be fixed by overriding the twig template for the style.

What I had been looking for was a formatter that had a bit of both worlds. It should use a twig template for easy override, but by default wrap lines according to the address' format.

I am submitting this issue, and have a patch I will post shortly, along with an explanation of what it does.

Comments

Dionsj created an issue. See original summary.

dionsj’s picture

StatusFileSize
new12.32 KB

This patch creates a new field formatter for the address field, I've based it on a copy of the default formatter and changed what I found to be necessary.
The patch also adds a template file for the new field formatter, I've tried to write a comment in the top to explain it to the best of my effort.

The field formatter uses the address format to define how to nest the address lines, it's a bit rough the way I've done it, so you're more than welcome to change it for something better.

As this is only my second patch, please feel free to tell me if I've done something wrong, or even improve upon my patch :).

dionsj’s picture

StatusFileSize
new12.63 KB

I had forgotten the theme variables addition in address.module, so here's an updated patch.

ptmkenny’s picture

Status: Active » Needs review
amaria’s picture

I'm getting this error:
Class 'CommerceGuys\Addressing\LocaleHelper' not found in Drupal\address\Plugin\Field\FieldFormatter\AddressPrettyFormatter->getValues()

Probably should be CommerceGuys\Addressing\Locale. At least in version 1.0.1.

dww’s picture

Status: Needs review » Needs work

To fix the error from #5.

I wish we didn't have so many different but nearly identical field formatters, each with confusing and/or vague names. I wonder if this can be turned into a patch to simply improve the "default" formatter to not make matters worse?

Thanks,
-Derek

pancho’s picture

Status: Needs work » Postponed (maintainer needs more info)

Indeed we need more info what the actual problem is with the current formatters. Not saying these couldn't be improved, but it remains totally unclear what this "pretty" formatter tries to achieve.

The default renderer wraps each address line nicely in it's own span with a class, making it easy to target and style. Yet it adds forced line-breaks (
) after each line, even if that line is empty.

Can't reproduce. Empty lines are omitted, no line-break forced.

The plain formatter outputs it all as plain text, where each address line is not wrapped. This can be fixed by overriding the twig template for the style.

That's exactly how it is meant to be. Works as designed.

What I had been looking for was a formatter that had a bit of both worlds.

Don't think that's a good idea. Why?

This patch creates a new field formatter for the address field, I've based it on a copy of the default formatter and changed what I found to be necessary.

Unclear what that is.

In the end, this patch is never gonna be picked up, unless somebody steps in to describe what exactly needs to be changed. Tending to Won't fix, still want to give the OP or someone else the chance to step in.

bojanz’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

I agree with Pancho.