I experienced a strange problem today:
I tried to change the "collection", saved in the admin settings form, to a new collection. However, I cannot change it, it always loads the initial value I've saved the first time. In other words, after saving the collection for the first time, I cannot change it any more.
After some investigation I found out that it's kind of a conflict with i18n variables. Basically I enabled i18n_variables module, which depends on variable / variable_store module and can save any selected system variables to multilingual versions, which is very useful.
In my case I want the GSA collection to change depending on the language, so I enabled the setting to let "Google Appliance default collection" to be managed by i18n variables.
However, the GSA module admin form was not saving the variables in a standard way, it was using non-standard form field names (without the googl_appliance realm prefix) in the admin form - google_appliance_admin_settings($form), then added a submit handler to save those variables manually. So when other modules try to alter the default way of load / save variables, this part is not being altered and always return the default value which is the first time saved value.
In my opinion, the additional saving in the custom submit handler is redundant as the system_settings_form() submit handler already saves any form values. And it's breaking other module's expectations.
I'm providing a patch that removed all the additional savings in the custom submit handler. By changing the field names in the admin form, I let system_settings_form() do the variable saving and it seems to be working just fine and even works with multilingual variables. Now I can have different GSA collections change automatically depending on the language.
For the variable loading part, it seems to be a little bit redundant as well so I removed the non Drupal 7 standard static variable loading part, as Drupal 7 do not use additional db queries when you call variable_get(), I just let the helper function always call varaible_get to retrieve the values.
Comment | File | Size | Author |
---|---|---|---|
#12 | google_appliance-variable_localization_support-1929708-12.patch | 0 bytes | iamEAP |
Comments
Comment #1
yang_yi_cn CreditAttribution: yang_yi_cn commentedhere is the patch.
Comment #2
mpgeek CreditAttribution: mpgeek commented@yang_yi_cn, this is a very nice simplification, the original logic was a holdover from the 6.x branch. A few tweaks:
Just comment on what the function is doing, not what the change is.
Clean up whitespace errors.
Comment #3
iamEAP CreditAttribution: iamEAP commentedFinally able to work on this. All of the above is great, but it I don't believe it's actually adequate to get it working with Variable / i18n Variable. For that, we'll need to implement hook_variable_info() and a few other bits from Variable API.
Patch forthcoming.
Comment #4
iamEAP CreditAttribution: iamEAP commentedEssentially #1, with minor comment/whitespace fixes with a google_appliance.variable.inc file and Variable API code.
Comment #5
Daluxz CreditAttribution: Daluxz commentedI noticed that this module saves all variables twice: one time prefixed with "google_appliance_" and one time without the prefix. This was probably caused by the custom submit handler in the admin form.
The patch in this issue fixes that too.
I rerolled the patch so it applies to the current dev-version. (so it's basically the same as #4)
I didn't test if this fixes the i18n-variables issue.
Comment #6
Everett Zufelt CreditAttribution: Everett Zufelt commentedI tested the most recent patch to resolve domain access compatibility. I had to re-roll to apply to 7.x-1.13.
After re-rolling the only extra step (likely needs to be added to the above patch) was that I noticed there is no defined constant for the language_filter_options value, and that it is not being loaded in the _google_appliance_get_settings() function (missing from the list of keys.
Without adding the language_filter_options to the list of keys that field will save, but fail to load (appears that you didn't save the settings even when they are saved.
Next time the above patch is re-rolled I recommend:
- Add the constant
define('SGA_DEFAULT_LANGUAGE_FILTER_OPTIONS', '');
- Add language_filter_options to the list of field keys in _google_appliance_get_settings()
- Add the same code as for block visibility to convert the empty string to a null array (as this value is the #options value for a checkboxes form element.
Comment #7
Everett Zufelt CreditAttribution: Everett Zufelt commentedComment #8
iamEAP CreditAttribution: iamEAP commentedThanks for the notes, @EveretteZufelt! Here's a re-roll of #5, with edits based on #6, and added hook_variable_info items for variables that have been added in the intervening months.
I'll be reviewing this on a fresh install as well as my own now.
Comment #9
iamEAP CreditAttribution: iamEAP commentedResolves issues related to the way error messages were being saved.
Moving on to testing i18n with this patch.
Comment #10
iamEAP CreditAttribution: iamEAP commentedi18n integration so far is flawless...
It seems reasonable to assume that someone may want to vary the "restrict searches to specified languages" configuration per language. Adding that in with this patch.
Comment #11
iamEAP CreditAttribution: iamEAP commentedSince this also fixes the double-variable save, we should also add an update hook to clean up the variables table...
Comment #12
iamEAP CreditAttribution: iamEAP commentedUpdate hook to clean up variables.
Comment #14
iamEAP CreditAttribution: iamEAP commentedThanks @yang_yi_cn for the report and initial patch, @Daluxz for the re-roll, and @EverettZufelt for the reviews! Your contributions are appreciated. I'm excited to finally get this bug fix / feature out the door.
I've committed #12 to dev, which will be released in the near future.