The locale module is being cleaned up to be used only for interface translation, and language awareness is almost all moved out to the respective modules (user, path, node, etc.) One thing that is particularly left in locale module is the field language fallback handling code. That is inherent to fields, just as user preferences for language or path language support is inherent to paths. We take an approach with Drupal 8 to not solve language problems from the outside but bake language right in to the modules. Fields already do their own language based storage (language being even part of the primary key on all field data tables), so it is logical to have the language base rendering also part of the fields infrastructure.
Tasks
- move field language negotiation code from locale.module to field.module
- move related tests from locale to field tests too
- do not make the feature/tests depend on locale module anymore (this might have other tests in the system related which rely on field language)
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | drupal-language_negotiation-1630264-23.patch | 25.33 KB | vasi1186 |
| #19 | drupal-language_negotiation-1630264-19.patch | 25.37 KB | vasi1186 |
| #19 | interdiff_11_19.txt | 3.08 KB | vasi1186 |
| #11 | drupal-language_negotiation-1630264-11.patch | 24.72 KB | vasi1186 |
| #9 | drupal-language_negotiation-1630264-9.patch | 19.61 KB | vasi1186 |
Comments
Comment #1
vasi1186 commentedComment #2
vasi1186 commentedA first patch to be reviewed.
The main changes I made:
1. I moved the locale_entity_info_alter() to the node module (basically put the translation handler in the hook_entity_info()), and also move the submit handler that was attached to the node form in the locale_form_node_form_alter() also in the node module because all that logic should reside in the node module and not the field module, IMO. Also, the field module is a Drupal required field, so it will be always enabled.
2. The locale_field_language_alter() and locale_field_language_fallback() were moved into the field module.
Comment #3
gábor hojtsyThis is strange (and I see it is pre-existing before the patch), but there is $display_langcode here, but once it is passed on as-is, it becomes $field_langcodes in the invoked function (multiple langcodes).
The code gets to this point I think even if there is no language module enabled. We should somehow stop this invocation chain at a point if the language module is not there (or prove it will not get here :)
Can/should we say this independent of language module being enabled?
Function summeries should be on one line, extended comments should be on other lines followed by an empty line.
Comment #4
vasi1186 commentedFor the 4th point, I implemented the change in the attached patch.
For the 3rd point, I wrapped now that translation handler into a module_exists() check, so, if the language module is not enabled, the field_language translation handler should not be assigned to the node.
By doing this, basically the 2nd point is also solved, because the field_language_fallback() function is called only if the entity type has the field_language translation handler attached (except the case when a custom module would alter the entity definition and always add the translation handler...)
For the 1st point, I think the root of the issue is in the field_language() function, in field_multilingual.inc file. There, the $display_langcode is an array and not just a "simple" value. So, either we change the name of that variable to something like $field_display_langcodes (because $display_langcodes is already used), or change the field_language_fallback() function and use $display_langcode instead of $field_langcodes. I would choose the first option, what do you think?
Comment #5
vasi1186 commented#4: drupal-language_negotiation-1630264-4.patch queued for re-testing.
Comment #6
fubhy commentedThere should be a comma after "If so" => "If so, the requested language ..."
I don't like this function description.
"Handles possible node language changes if 'field_language' is registered as a translation handler."
New (capital letter after the ":").
Unused variable.
Comment #7
fubhy commentedThe last version of the patch is from me but it just changes a few comments and I already discussed it with the others at the sprint and it seems to be RTBC material now.
Comment #8
plachThe field translation handler name is supposed to be a module name. Actually Node is providing the code dealing with node field languages, hence we should probably go with
'node'instead of'field_language'. I'd suggest to just remove the translation handler name from thefield_has_translation_handler()call infield_field_language_alter(), this will provide language fallback for every entity type if there's at least a translation handler enabled for it.BTW, when we have an entity translation UI in core I would just drop the field translation handler concept altogether, since it has been introduced with the idea that we would have no UI in core for translatable fields.
field.test already has a bunch of tests for generic field language support. This one should totally go in node.test.
Comment #9
vasi1186 commentedAttached a patch to implement the changes from #8.
Comment #10
plachJust a minor thing: no new line at the end of the file. Otherwise looks good, great work!
Comment #11
vasi1186 commentedFor some reason, after making the diff on the latest d8 version, the patch got much bigger, but it should work as before...
Comment #12
plach#11 actually deletes
LocaleMultilingualFieldsTest, which actually #9 didn't do. RTBC if the bot is happy.Comment #13
gábor hojtsyIn that case, tabididu!
Comment #14
catchField is a required module, can never be uninstralled, and I'm sure it has other variables that aren't cleaned up like this, so this should be removed unless we start properly putting in hook_uninstall() to all required modules.
Is it OK to continue defaulting to TRUE here if this is baked into the field system. If I only have one language on my site won't that mean extra code to run?
Also any particular reason to have field module implementing it's own alter hook?
Comment #15
vasi1186 commentedFor the first comment, I will remove the hook.
For the 2nd observation: I think it is good to default to TRUE, even if there is some extra code to run in case there is only one language, because then if the site has more languages, then people will have to know that they must set that variable to TRUE in order to have this functionality.
Regarding field implementing it's own alter, dont't really have a particular, strong, reason for that... I can move the code into the field_language() function itself if you think this would be better...
Comment #16
fubhy commentedI think you forgot to upload your patch or accidently set it to 'needs review'
Comment #17
vasi1186 commentedyes, accidently set it to "needs review", I think it was preselected...
Comment #18
gábor hojtsySo the previous code never set 'field_language_fallback' to FALSE either, it was always TRUE, but merely by being in the locale module, it was only effective when the module was on. Now it would always be effective (unless specifically set to FALSE), so it will be down to field_has_translation_handler() to figure out you don't have a translation handler and return FALSE. That sounds like the logic change really. I think @plach did not want to use module_exists() or anything else because that makes it less pluggable.
I'm also fine with not implementing an alter hook and putting code in right away.
Comment #19
vasi1186 commentedAttached a patch with these changes:
- removed the hook_uninstall for the field module.
- removed hook_field_language_alter() from the field module and put the logic in the field_language() itself.
- by default, "field_language_fallback" is FALSE and the value is updated in hook_language_insert() and hook_language_delete().
Comment #20
vasi1186 commented#19: drupal-language_negotiation-1630264-19.patch queued for re-testing.
Comment #21
gábor hojtsyLooks like you have the same code basically in the insert and update hook. It was just one call before, but now its more code and comments. What about unifying those and calling one from the other?
Comment #22
gábor hojtsyWe discussed in person that due to the order of the hooks invoked, it is required to have slightly different code/conditions in the two hooks. So as it was RTBC before with review from various people and the concerns are addressed, back there.
Comment #23
vasi1186 commentedRerolled the patch for the latest version of d8
Comment #24
gábor hojtsyStill looks good, thanks for the reroll.
Comment #25
gábor hojtsy#23: drupal-language_negotiation-1630264-23.patch queued for re-testing.
Comment #26
webchickCool, this looks like sensible clean-up.
I had one question about this:
I was worried that this would result in a lot of unnecessary variable_set() calls, but it was pointed out that this hook only fires when languages are deleted/inserted manually, which will be relatively rare.
Committed and pushed to 8.x. Thanks! :)
Comment #27
webchickComment #28
gábor hojtsyDone, so removing sprint tag. Thanks!
Comment #30
andypostFiled related issue #1977790: Drop node_entity_info_alter() as unused
Seems translation key could be now removed in favor of controllers