Redundant comma in address_plain formatter when locality is empty

Created on 14 December 2024, about 2 months ago

Problem/Motivation

The address-plain.html.twig template adds an unnecessary comma to the generated address text when the locality variable does not have a value. This happens because the template only checks if locality is not iterable ({% elseif locality is not iterable %}), without verifying if the variable contains any value.

This leads to formatting issues in the address, resulting in output such as:

, Ankara, Turkey

The extra comma is unnecessary and affects the presentation of the address.

Steps to reproduce

  1. Use the address-plain.html.twig template to render an address.
  2. Ensure the locality variable is empty.
  3. Observe that the output includes an unnecessary comma for the locality field.

Proposed resolution

Update the condition for rendering locality to:

  1. Check if locality exists.
  2. Determine if locality is iterable and contains elements.

The corrected code for the locality block could look like this:

{% if locality.name %}
  {{- locality.name -}},
{% elseif locality.code %}
  {{- locality.code -}},
{% elseif locality and locality is not iterable %}
  {{- locality -}},
{% endif %}

This ensures that locality is only rendered when it has a valid value, avoiding unnecessary commas.

Remaining tasks

  • Update the address-plain.html.twig template with the proposed changes.
  • Test the updated template with various cases:
  • Submit a patch or merge request with the fix.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Needs review

Version

12.4

Component

Code (back-end)

Created by

🇹🇷Turkey makbay

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024