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
Issue fork languagefield-3542424
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
Comment #3
stefan.kornComment #5
johnvCommitted 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?
Comment #6
stefan.kornThanks 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.
Comment #7
johnvThanks, I created
#3542685: Add languageicons to Widget values
and
#3542683: Add SelectWidget formatting options to AutocompleteWidgets
Comment #8
johnvPlease confirm if current codebase deserves a new version, of if you think it needs a bit extra
Comment #10
nagy.balint commentedI 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:38as the commit introduced
but TranslatableMarkup is not in the "use" section.
Comment #12
johnvThanks, it should work, now.