The locality.name data is missed in PlainFormater

Created on 25 May 2017, about 7 years ago
Updated 10 January 2024, 6 months ago

There two issues.

The first is very simple, missed the variable in address\templates\address-plain.html.twig.

The second issue related if in "Manage fields" was unchecked "Administrative area" so in this case "Administrative area" always empty and in address\src\Plugin\Field\FieldFormatter\AddressPlainFormatter.php works break in foreach.

I submit a patch.
Many thanks for a beautiful module.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Ruslan Piskarov Kiev, Ukraine

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States mmenavas

    It looks like I'm not the only one who is happy with the patch. What's keeping it from being merged?

  • πŸ‡ΊπŸ‡¦Ukraine Ruslan Piskarov Kiev, Ukraine

    I use this patch for 6 year for all projects. Will be nice if it will be merged.

  • Status changed to Needs work about 1 year ago
  • πŸ‡·πŸ‡ΈSerbia bojanz

    We're still missing a test.

  • πŸ‡©πŸ‡ͺGermany marcusx

    For "Italien" Addresses there is no locality.code. The locality name is just a string in 'locaity'. And what does code in this context mean? I understand "code" for the country is the ISO shortcut. But why would the city name e.g. "Berlin" for a German address be in `locality.code` and not `locality.name` ?

    See:

  • Assigned to sickness29
  • Status changed to Needs review 8 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 8 months ago
    32 pass, 2 fail
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    Added only tests per @dww comment that check plain address formatter ,so this should fail.
    There are 2 tests: one to check if all address data present in plain formatter output and the other checks if all data is shown when some property is optional and empty (apart from country_code which determines empty field).

  • Issue was unassigned.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 8 months ago
    34 pass
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    Now I apply same tests from #17 with fixes from #9 into one patch.
    This should now pass.

  • Status changed to Needs work 7 months ago
  • πŸ‡·πŸ‡ΈSerbia bojanz

    For "Italien" Addresses there is no locality.code. The locality name is just a string in 'locaity'. And what does code in this context mean? I understand "code" for the country is the ISO shortcut. But why would the city name e.g. "Berlin" for a German address be in `locality.code` and not `locality.name` ?

    The template file that you're modifying tells you this:

     * if a subdivision (dependent_locality, locality, administrative_area) was
     * entered, the array will always have a code. If it's a predefined subdivision,
     * it will also have a name. The code is always preferred.
    

    This is because if a subdivision is predefined, it has two names, "name" which is supposed to be used in the UI when selecting a value, and "code" which is supposed to be shown when rendering an address. Sometimes this "code" matches the "name", sometimes it matches an ISO code, depending on the rules for that country. The use of "code" to mean user-facing label is unfortunate, but we inherited that decision from Google 10 years ago and we can't change it.

    We can extend the comment in the template file to explain what I just explained here.

    @sickness29
    Thank you for illustrating a case in which the current code fails, something I've been asking for since 2019.

    However, we already have a AddressPlainFormatterTest in Drupal\Tests\address\Kernel\Formatter, can we add a new test case there instead of introducing an independent test?

    Furthermore, the twig file changes don't seem correct, the twig file now looks like this:

      {% if locality.name %}
        {{ locality.name }} <br>
      {% endif %}
      {% if dependent_locality.code %}
        {{ dependent_locality.code }} <br>
      {% endif %}
      {% if locality.code or postal_code or administrative_area.code %}
        {{ locality.code }} {{ postal_code }} {{ administrative_area.code }} <br>
      {% endif %}
    

    So we output the locality, then the dependent_locality, then the locality again?

    I still think this patch should not make any changes to the twig file itself, nor should it switch "code" for "name" in the formatter plugin.

  • Status changed to Needs review 6 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 6 months ago
    35 pass, 1 fail
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    Hi @bojanz
    I have added changes to Kernel\Formatter\AddressPlainFormatterTest to illustrate the issue in test failure.
    When only country and admin area were selected, there is no admin area in output, however it should be as we allow optional values.
    I will add this same test with fix as next comment

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 6 months ago
    42 pass
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    The issue with output should now be fixed

  • Status changed to Needs work 6 months ago
  • πŸ‡·πŸ‡ΈSerbia bojanz

    Fix looks great now. Needs a reroll though, πŸ“Œ Usage of content language instead of the language of the interface. Needs work changed the tests.

  • πŸ‡·πŸ‡ΈSerbia bojanz

    Committed #21 to 8.x-1.x, changing version to focus on the 2.0.x reroll.

  • Status changed to Needs review 6 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 6 months ago
    43 pass
  • πŸ‡·πŸ‡ΈSerbia bojanz

    Rerolled.

    • bojanz β†’ committed 38289a64 on 2.0.x
      Issue #2881391 by sickness29, Ruslan Piskarov, bojanz: The locality.name...
  • Status changed to Fixed 6 months ago
  • πŸ‡·πŸ‡ΈSerbia bojanz

    And committed.

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

Production build 0.69.0 2024