Consider integrating with (or being inspired by) Country module to improve Add/Edit Country UX

Created on 8 November 2024, 14 days ago

Motivation

The Country module exists and looks in good health. It provides a field for storing a 2-letter ISO country code, an autocomplete widget and a select form element that uses core's standard list of countries for its options.

It seems like a natural fit here to use this to improve the UX for adding countries.

I can think of three ideas in this regard:

  1. Hard-dependency: Use the Country Field type/widget for the country_code property
  2. Optional dependency: Use the Country Field Element on the form (if the module is installed) while falling back to the current textfield if not.
  3. Take inspiration, introduce no dependency: Given how simple the country select list is LCN could simply turn its country code form element into a select that takes its options from core's standard list in the same fashion, without introducing a new dependency.

In my opinion, LCN should also consider removing the name field from Country. Would it not be sufficient to implement Country::label() and report the name that matches its 2-letter country code from core's standard list? Is there a realistic use case where someone would wish to pick a standard country but not use the standard name for it?

One downside of this suggestion is it becomes more difficult to use a non-standard country code for a Country. Here are some thoughts about that:

  1. Core's list of countries goes through hook_countries_alter(), so new country codes (or altering of names, actually) can be done by custom code. We could add a note to the README/Project page to install Country Alter UI if site builders wish to do this in the UI.
  2. The most common reason to customize the 2-letter country code is to control the URL prefix used by the Language-country URL Language Negotiation Method. I suggest this would be better handled by configuration on NegotiationLanguageCountryUrlForm, which could provide means for the site builder to specify a custom url prefix for each country, or each language, or even each language-country pair (this idea is also suggested in the last paragraph of #3486180-8: Does not support langcode url prefixes more complex than 2 letters (e.g. zh-hans, zh-hant, haw) ).

User interface changes

On the Add/Edit country form, replace the Country name and Country code fields with a single Country field:

Data model changes

Perhaps to some fields on the Country Content Entity Type (depending on the chosen integration, see above).

Feature request
Status

Active

Version

1.0

Component

User interface

Created by

🇬🇧United Kingdom jamsilver West Midlands, UK

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

Comments & Activities

Production build 0.71.5 2024