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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | add_a_pretty_field-2912629-3.patch | 12.63 KB | dionsj |
| #2 | add_a_pretty_field-2912629-2.patch | 12.32 KB | dionsj |
Comments
Comment #2
dionsjThis 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 :).
Comment #3
dionsjI had forgotten the theme variables addition in address.module, so here's an updated patch.
Comment #4
ptmkenny commentedComment #5
amaria commentedI'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.
Comment #6
dwwTo 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
Comment #7
panchoIndeed 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.
Can't reproduce. Empty lines are omitted, no line-break forced.
That's exactly how it is meant to be. Works as designed.
Don't think that's a good idea. Why?
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.
Comment #8
bojanz commentedI agree with Pancho.