The locale admin UI for languauges has all of its code hardcoded to update the existing languages. It should use the real APIs introduced with #1260510: Introduce a language_load($langcode) and #1215716: Introduce locale_language_save().
The main code in question is at: http://api.drupal.org/api/drupal/modules--locale--locale.admin.inc/funct...
Comments
Comment #1
gábor hojtsyTagging.
Comment #2
svendecabooterAssigning to me
Comment #3
svendecabooterHere is a patch that uses the proper API function that was introduced in #1215716: Introduce locale_language_save().
Comment #4
gábor hojtsyThis is unfortunately not so simple :) It is not going to work like this. You need to load the object first, overwrite its values as appropriate and then save. If you save it without its other values that are not present in the form, you got to remove those things...
Comment #5
svendecabooterThat makes sense :)
The following patch seems to do the trick. This also assumes this patch of course: #1260510: Introduce a language_load($langcode)
Or am I still missing something obvious?
Comment #6
gábor hojtsyMuch better. :) Not obvious, but you are missing that the _save() issue has complete handling for changing of the default language, so that part of the code is entirely superfluous with the _save() implementation :) That function has this for default languages with the patch applied:
So we can get rid of that up to the form redirect. Then also I'm not sure why do we need a return; at the end of the function, looks like cruft (not your mistake of course, but why not remove it?)
Comment #7
svendecabooterAh hadn't noticed that code in the other patch.
However, upon testing this, the code there doesn't seem to be correct, as $language->default is not set (at least in my setup).
I'm trying to debug that first... Or am I missing another patch that adds in the "default" parameter afterwards, if appropriate?
Comment #8
gábor hojtsyWell, it should come from the database via your language_load() in your patch. It is not in the form definitely.
Comment #9
svendecabooterOk, so this property should be added to the $language object, specifically for this case?
I figured it would make more sense if language_load() would set this property, so it could be used in other scenarios as well...
Anyhow, here is a new version of the patch that gets this working.
Comment #10
svendecabooterComment #11
gábor hojtsyYou are right, this is missing from language_load(). I think this should indeed go to language_load, not here. Let's assume here that the load patch does this and get @andypost include it in the load patch :)
Comment #12
svendecabooterFair enough :)
Here is a new patch, assuming this gets fixed in language_load().
Comment #13
gábor hojtsyI think this looks pretty good. It needs the load to land of course, but its basically nice and dandy :) Much nicer than before the patch :)
Comment #14
andypostWe should decide on storing a default language. #1260510-7: Introduce a language_load($langcode)
Have it as {languages}.default seem preferable because we could use a transaction for saving|changing default but it could break a lot in contrib
Comment #16
gábor hojtsy@andypost: yeah, we can easily assure we have one default language now that we have it in a variable, but depending on the settings' storage in the future it might or might not be possible to put in a transaction. I think we should follow along here and not try to figure out all pieces at once. Going in smaller pieces helps us solve some real problems and allow us to focus on the remaining ones later instead of trying to deal with a huge mass of stuff.
Comment #17
gábor hojtsyNote that this should also be applied to the language overview submission page: http://api.drupal.org/api/drupal/modules--locale--locale.admin.inc/funct...
Comment #18
svendecabooterGood catch.
Here's an updated patch that uses the proper API function in both places.
Comment #19
gábor hojtsyLooks good, however, I think we can get rid of the cache_clear() and module_invoke_all() at the end. I think this is the last multilingual_settings_changed piece and we can kill it from the locale.api.php now that we don't use it (coupled with the patch to save the language). If you see other uses of it, don't remove it, but otherwise, please do :) The save API will invoke the right hooks to inform other modules per language and it will clear the cache proper as well, so we don't need those here.
Otherwise I was concerned about whether the data we get from language list are full language objects, so we can just send them to be saved. Looks like we might actually have that data, so great :)
Comment #21
svendecabooterThis patch is now merged into #1215716: Introduce locale_language_save(), since the UI code only really needs locale_language_save() anyway.
Comment #22
gábor hojtsyTagging for base language system.
Comment #23
gábor hojtsyAdding UI language translation tag (both this one and language-base apply).
Comment #23.0
gábor hojtsyAdd parent issue