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.

CommentFileSizeAuthor
#7 address_3497225-7.patch624 bytesoheller

Issue fork address-3497225

Command icon 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

douggreen created an issue. See original summary.

douggreen changed the visibility of the branch 3497225-plain-text-formatter to hidden.

douggreen changed the visibility of the branch 3497225-plain-text-formatter to active.

oheller’s picture

StatusFileSize
new624 bytes

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

douggreen’s picture

MR!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.

douggreen’s picture

Issue summary: View changes

douggreen changed the visibility of the branch 3497225-plain-text-formatter to hidden.

oana.hulpoi’s picture

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

oheller’s picture

Status: Active » Needs review

It looks good to me, but someone else should test and validate the change.

darren oh’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed the fix works.

abhuman’s picture

Also can confirm the fix works.

tbkot made their first commit to this issue’s fork.

shivansunfire’s picture

It's been almost a year in RTBC, please could one of the maintainers commit this into the project and release it?

dww made their first commit to this issue’s fork.

  • dww committed b425bde0 on 2.1.x authored by douggreen
    fix: #3497225 Plain Text Formatter does not set Locality properly...

  • dww committed e347435e on 2.0.x authored by douggreen
    fix: #3497225 Plain Text Formatter does not set Locality properly...
dww’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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