Problem/Motivation

The setting "Display in widget" for "Language select list" widget (languagefield_select) does not have any effect currently.

The code seems to be copied to some extent just from the field formatter. But field widget is working differently.

I suppose for field widget the "Display in widget" settings should define what to show as label of the option in the select field in form mode. The value of the option should stay on the langcode.

Steps to reproduce

Try different settings for "Display in widget" like ISO, native name and combinations thereof with name. Note that the output in field widget is always the "name" of the language, not considering ISO or native name.

Proposed resolution

Add some code to output the option label based on the setting for "Display in widget"

Remaining tasks

User interface changes

option label of field widget shows naming as defined in widget settings.

API changes

Data model changes

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

stefan.korn created an issue. See original summary.

stefan.korn’s picture

Status: Active » Needs review

  • johnv committed 0723f63c on 8.x-1.x
    Issue #3542424: Language select list widget - setting has no effect
    
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.14
Status: Needs review » Fixed

Committed with credits in the issue. Thanks.

The patch became much bigger when testing:
- adding defaultSettings();
- encapsulating the value formatting in one function, both for formatter and widget.

Icons are still not supported in widget. I guess that is not possible, since select widget supports only a ascii string?

stefan.korn’s picture

Thanks for quick commit and refactoring the code.

Yeah, icons might be difficult in select list.

Maybe like this: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extension...

Or maybe using Unicode emoji flags, like so: https://gist.github.com/chrisjonesio/2f693fd9853c5450345e18c836577393

But that surely is a bigger feature request. Maybe if I find the time ... The unicode emoji flags seem like an interesting thing more generally. Like having a service or library that returns you the flag emoji if you pass ISO 3166 code or something like that.

johnv’s picture

Please confirm if current codebase deserves a new version, of if you think it needs a bit extra

  • johnv committed c803654c on 8.x-1.x
    Issue #3542424: Better formatter, widget settings summary
    
nagy.balint’s picture

I believe this commit broke the module, since
Fatal error: Uncaught Error: Class "Drupal\languagefield\Plugin\Field\FieldType\TranslatableMarkup" not found in languagefield/src/Plugin/Field/FieldType/LanguageItem.php:38

as the commit introduced

  label: new TranslatableMarkup("Language"),
  description: new TranslatableMarkup("An entity field to store a custom language."),

but TranslatableMarkup is not in the "use" section.

  • johnv committed 491ef5a0 on 8.x-1.x
    Issue #3542424 by stefan.korn, johnv: fix missing include
    
johnv’s picture

Thanks, it should work, now.

Status: Fixed » Closed (fixed)

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