Closed (fixed)
Project:
Custom Language field
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Oct 2014 at 18:18 UTC
Updated:
29 May 2017 at 19:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kitikonti commentedComment #2
kitikonti commentedComment #3
johnvThis sounds like a good idea. But the patch adds a new hook, making the system heavier.
How about this:
- in the widget settings, add a new language code 'zus => "users current language" ' in the list of languages;
- in the widget, when setting the '#default_value', determine the correct value for language code 'zus'.
Perhaps we should request a new language code in Drupal Core - language system. In D8 already 'und' and 'zxx' exist.
Comment #4
kitikonti commentedI understand the idea of your approach but i dont understand the way you want do this? You want that i remove my new hook but then you write to add a new option in the widget settings? How should i do this without a new hook?
I think what we want is to ONLY add the "Current language" option to the field settings form where you select the default value. But to do this i also need a new hook (the same as i already use). And on every other form if "Current language" was selected as default value, we remove this option and instead set the current language as default value.
Comment #5
johnvPlease review my attached version.
Indeed, the extra hook is needed, because languagefield does not use its own widget.
- Your 'preselect' option might be better for the sitebuilder, since it is more explicit. My extra 'zuser' option is a bit underwater.
- My version uses $user instead of $language. I think it is clearer, because with $language, it is not clear (to me) if you only have 1 site language or N user languages.)
In your use case, is the user language only a proposal, or is it forbidden to choose another value?
Comment #6
johnvI've created issue #2364503: Add a "User's default language" value.
Comment #7
kitikonti commentedI have not tested your patch now, maybe i could later today. I dont understand now our/your goal? You wrote that you like my idea more than the "Current user" version, but your patch uses the "Current user" version?
And the other question is, does $user and its language property always exists or only for authenticated users?
In my use case the user never sees the field, i have restricted its access with the field permissions module. Maybe we should add some documentation for this use case.
I use the language field to get the language of guests who makes a request to a product, and answer in their language.
Comment #8
johnvIndeed, my patch uses an extra language in the language list, instead of an extra checkbox, but it is too obfuscated (?). Itis a proof of concept.
About the language choice:
- in my test I change the language of the authenticated user, so the language is in the $user object.
- in your situation your anonymous user has choosen a site-wide language. I did not test that.
My point was: to me, in your first patch, it was not clear if the language could change depending on the users settings.
(I'm not sure if this post has made anything clearer :-)
Comment #9
johnv@kitikonti, I'm investigating this in the D8-version, and have patches coming up.
In D8, 3 new options exist:
- default language (the language upon installation)
- interface language (via language switcher or else)
- users preferred language (via user settings)
These cover both the use cases in your an mine patch.
Also, in latest dev-release, the language select in the field settings is multi-value now since #2116687: Using new (custom) languages AND predefined languages got in. So a new checkbox 'preselect' is not necessary, as I'll extend the current list of (3) options.
Patches coming up soon.
Comment #10
kitikonti commentedOk, sry that i had currently not time to test your patch.
Comment #13
johnvThis is now added to the D7-version and the D8-version.
Comment #14
kitikonti commentedCould i also get a patch for the d7 version? I dont really want to use the dev version on a production site. Thx for your work.
Comment #15
johnvIf you test and accept the current version, I will release an official release. or you can open #12. For some reason the version is not shown in the automatic comment.
Comment #16
kitikonti commentedOk i will do a test in a view minutes.
Comment #17
kitikonti commentedSo i tested with the latest dev and i found a problem and made some minor changes.
If i use "current interface language" as default language i get an error on line 399 because $value has no element with the key 'value'. I dont really know if there are other cases but in my case $input is the array and $value in the foreach is just a string. So i removed the ['value'] two times. This works in my case, it then calls the _languagefield_getLanguageConfigurationValues function which uses the 'current_interface' case and returns the current language.
On line 385 you have a if statement with no actions, which is the exact same statment than the previous one. So i removed this. But this will run into another problem, because the following else statement, which i think we dont need, wont be executed. Because $input has always a value at this step we dont need the else statment, if it was empty it would get set in the if statement before.
On line 630 we should not use 'und', instead use LANGUAGE_NONE, which is the same.
Comment #18
johnvJa, the code is wrong. See below how I meant it (the first part). (I have no access to Drupal ATM)
Comment #19
kitikonti commentedAhh ok so the conversion from "current language" to the "language code" do not happen on displaying the widget. It will get converted after submitting (the else statement). I am currently not on my dev desktop, but i think this would work. Maybe i could test it later today.
Comment #22
johnvIndeed, the [#value_callback] executed both on showing and on committing the widget. (In D8, the massageFormValues() method is used.)
The current dev-version should work. I only doubt if we should expose the user with the technical names in the options list and the default value.
But that is UX.
Comment #23
kitikonti commentedSo tested this again and run into another problem. If the user creating the node has not access to the languagefield (this is my case, because of field permissions module) $input is false on submitting. So in the _languagefield_widget_value function it will pass the first if statement. In this statement we just pass the blank default value to $input (in my case current_interface) which leads in a db error message because 'current_interface' string is too long for the db field column.
I dont know if you will do a fix for this because this is just my use case, but a db error is also not nice. I suggest to use the _languagefield_getLanguageConfigurationValues function also in this first if statement, so we always get a useable language code for the db.
I also found another problem, but i think this should be discussed in a new issue. Currently this field could not be used as multivalue field. For example if you set multiple default values only one will be used.
Comment #24
johnvChanging the value upon showing the widget seems fine. However, I tested the multiple value use case (which was wrong in first instance) but i thought it was corrected in #20. Can you provide a pstch for that?
Comment #25
johnvChanging the value upon showing the widget seems fine. However, I tested the multiple value use case (which was wrong in first instance) but i thought it was corrected in #20. Can you provide a pstch for that?
Comment #26
kitikonti commentedI dont know what you mean with
Do you mean the comment #20? So the latest dev release?
Comment #27
johnvYes. Before #20 it was wrong, as you described earlier. #20 contains a fix for multivalue.
Comment #28
kitikonti commentedOk, i dont have time until next week, so if its still open than i will have a look on it.
Comment #29
johnvPerhaps your problem is that in the fist part of the function, we do not difference between single and multivalue, as we do in the second half.
Comment #30
kitikonti commentedYes i know that this is the problem, but have not tried any solution yet.
Comment #32
johnvHmm, you're making it difficult in #23.
Adjacent patch makes some things better, but still will not work for your situation, where the widget apparently is not submitted.
That cannot be handled in the widget, but in some hook_field*() hook.
Comment #33
johnv@kitikonti , let's close this issue. We can re-open a new issue regarding #23 when needed.