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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yang_yi_cn’s picture

here is the patch.

mpgeek’s picture

Status: Needs review » Needs work

@yang_yi_cn, this is a very nice simplification, the original logic was a holdover from the 6.x branch. A few tweaks:

+++ google_appliance.helpers.inc	(working copy)
@@ -23,21 +23,14 @@
+ * variable_get() already cached by Drupal and will not use ¶

Just comment on what the function is doing, not what the change is.

+++ google_appliance.helpers.inc	(working copy)
@@ -50,23 +43,21 @@
+  foreach ($field_keys as $field) {  ¶
+    $settings[$field] = variable_get(
+      'google_appliance_' . $field,
+      constant('SGA_DEFAULT_' . strtoupper($field))
+    );
+  }
 
-    // The empty string in the define block above for block visibility 
-    // settings is really just a flag that nothing has been set yet. 
-    // Using an empty string is problematic, so we just set it to an 
-    // empty array instead.
-    if ($settings['block_visibility_settings'] === '') {
-      $settings['block_visibility_settings'] = array();
-    }
+  // The empty string in the define block above for block visibility ¶
+  // settings is really just a flag that nothing has been set yet. ¶

Clean up whitespace errors.

iamEAP’s picture

Finally 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.

iamEAP’s picture

Status: Needs work » Needs review
FileSize
14.85 KB

Essentially #1, with minor comment/whitespace fixes with a google_appliance.variable.inc file and Variable API code.

Daluxz’s picture

Version: 7.x-1.11 » 7.x-1.x-dev
FileSize
14.57 KB

I 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.

Everett Zufelt’s picture

I 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.

Everett Zufelt’s picture

Status: Needs review » Needs work
iamEAP’s picture

Thanks 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.

iamEAP’s picture

Resolves issues related to the way error messages were being saved.

Moving on to testing i18n with this patch.

iamEAP’s picture

i18n 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.

iamEAP’s picture

Since this also fixes the double-variable save, we should also add an update hook to clean up the variables table...

iamEAP’s picture

  • iamEAP committed 89b39c0 on 7.x-1.x authored by yang_yi_cn
    Issue #1929708 by iamEAP, yang_yi_cn, Daluxz: admin settings form cannot...
iamEAP’s picture

Status: Needs review » Fixed

Thanks @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.

  • iamEAP committed ac2b3c2 on 7.x-1.x
    Small fix / follow-up for #1929708.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.