Problem/Motivation
When there is an administrative area and a locality, the AddressPlainFormatter only adds the code and name to the administrative area and not the locality such that when in ./templates/address-plain.html.twig you cannot access {{ locality.code }} but instead would have to use {{ locality }}.
Steps to reproduce
1. Create a new content type.
2. Add an address field to the new content type, hiding all fields except for the administrative area and locality. Change the display to use the Plain text formatter.
3. Add a node of this new content type, filling in all fields.
4. Note that the locality is not displayed in the output.
Proposed resolution
Remove check at the bottom of the
if (!$subdivision->hasChildren()) {
// The current subdivision has no children, stop.
break;
}Remaining tasks
None. See MR!65.
User interface changes
Fixes UI bug.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork address-3497225
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #7
oheller commentedI can confirm that the above code returns $values as either a string or an array. We are overriding the template in our theme to access {{ locality.code }} which breaks when $values is a string. Attached is the patch removing the code.
Comment #8
douggreen commentedMR!65 does the same as the attached patch, and adds test data. I originally opened MR!64 against the wrong branch, closed it, then opened MR!65. I don't know how to make Drupal show the new MR as the primary MR for this issue. If anyone knows how to do that, please do so.
Comment #9
douggreen commentedComment #11
oana.hulpoi commentedThank you, @oheller!
The patch from #7 to remove the hasChildren() check in the AddressPlainFormatter resolves the issue.
I encountered this exact problem where address plain templates using {{ locality.code }} would break with the InvalidArgumentException. The fix ensures that locality data is consistently structured as an array with code/name keys.
I tested it with US addresses.
Comment #12
oheller commentedIt looks good to me, but someone else should test and validate the change.
Comment #13
darren ohConfirmed the fix works.
Comment #14
abhuman commentedAlso can confirm the fix works.
Comment #17
shivansunfire commentedIt's been almost a year in RTBC, please could one of the maintainers commit this into the project and release it?
Comment #21
dwwThanks! Did more reviews and local tests. Merged to 2.1.x and cherry-picked to 2.0.x. This will go out in 2.0.5, due out imminently.