Only show the language widget on entity forms when more than one language is available

Created on 2 August 2023, about 1 year ago
Updated 9 November 2023, 10 months ago

Problem/Motivation

Sometimes you want set up content so it can have different source languages, but you only have one enabled language on a site.

An example would be updating an existing site to have multi-lingual content, but not wanting to enable additional languages yet.

In this case, with locked languages set to not show, you can end up with a select list with one option i.e. 'English', this looks a bit broken.

Steps to reproduce

Proposed resolution

Only show the widget if there are two or more options to choose from.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Language module 

Last updated 1 day ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @catch
  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,946 pass
  • 🇬🇧United Kingdom catch

    No test coverage yet but here's what the change itself looks like.

    A counterpoint would be that if you've mistakenly only got one language, having the somewhat useless element might be a hint as to what the problem is, but personally I think the tidier form outweighs this.

  • last update about 1 year ago
    29,946 pass
  • 🇷🇴Romania amateescu

    The counterpoint mentioned in #2 seems like a valid argument, so this probably needs usability review. Otherwise the patch makes sense from a developer's point of view :)

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Agree this seems like a good update to have.

  • 🇫🇮Finland simohell

    There are a few different points of view to this, especially if single language is only a temporary phase.
    - Having less information on the form vs. having the form change.
    - The same effect could be achieved by not showing the language selector on the form. It may be confusing if site builder adds the language selection to the form but this does not appear.
    - There may be modules that restrict languages per user (maybe Allowed Languages does this) or some other use cases where language information is useful to have even if only one option.

    I would go with a softer approach by making this configurable and on by default. We already have a setting for including "Not specified" and "Not applicable".

    Current:

    New version:

  • 🇫🇮Finland lauriii Finland

    I'm not sure how often the configuration proposed in #6 would actually be useful. Since it's unclear if the configuration option would be helpful, I think we should first try to go with an approach that doesn't provide the configuration option. We can always add that later if it seems something that's worth adding.

    Given that the "Include locked languages" setting is enabled by default, we could try to address #2 by displaying a warning in the widget settings when the checkbox is disabled and there's only single language.

    I guess there's another way to get to this point which is that you remove a language, but that seems something that happens less often. That said, it makes sense at least to me that if I have only one language left, that I can no longer select the language.

    FWIW, the language switcher block already has this functionality. See \Drupal\language\Plugin\Block\LanguageBlock::blockAccess.

  • 🇫🇮Finland simohell

    There is actually also an existing setting content type / vocabulary. For "An example would be updating an existing site to have multi-lingual content, but not wanting to enable additional languages yet." one would just fix the language appropriately for the content and uncheck the box "Show language selector on create and edit pages".

    I am a little bit confused in which real world scenario this proposed code change would really be useful compared to existing configuration. I wonder if there is something I'm missing from the problem description? I'm looking at this from node/term perspective. I didn't check where else this would affect the site.

    Having intentionally enabled translation, decided to show the widget but then use code to hide the widget feels a bit odd a combination. When one enables translation there is already decision wether or not to allow selecting the language.

    A couple of lines of code isn't much and doesn't slow down the system so that it could be noticed by the human eye and uses hardly any extra electricity, but it is still a bit extra to save a few clicks on edge cases. Current version supports also starting to allow languages gradually but just not site wide change with a single click. Then again the change would usually go to production via CI/CD pipeline in configuration yamls.

    But it's not a big deal, I guess.

Production build 0.71.5 2024