As part of my efforts trying to integrate domain variables with multilingual variables, I started work on a generalized admin interface for variable realms. For more info see #1559970-6: Battle plan / Progress and #1307058-15: Use new Variable API for different variables per domain..

Situation

  • The i18n_variable module uses hook_form_alter() to adjust system forms, annotating multilingual variables, adding a language switcher on top and a custom submit handler for saving multilingual variables to the variable_store. These type of annotations would also be useful for other modules providing realms (e.g. domain module)
  • It uses hook_module_implements_alter() to ensure that the i18n_variable implementation of the hook is executed last. This makes it fairly difficult for other modules to override or adjust the forms (need to alter registry + make sure module weights are correct).
  • The i18n_variable module provides an interface for choosing which variables should be treated as multilingual variables. This would also be useful to have for other realms.

Proposed solution

Generalize i18n_variable_form_alter() and the variable selection form, to work for any realm and provide a central place for configuration...

For that purpose I have created a new module "Variable Realm Admin". I am going to upload a respective patch in a minute. For some screenshots (domain+variable usecase) see #1559970-6: Battle plan / Progress.

Concepts/ Implementation details:

  • Extend variable_realm_info with any information required to build the admin interface.
  • A variable realm "has settings", if variables need to first be selected as being "available for the realm". Realms which do not have settings are not handled/affected by the module (e.g. the global/default realm).
  • A variable realm can have a "settings ui", which means that there will be page for selecting variables. TRUE by default, but can be disabled on a per-realm basis if needed. The list of variables available in the selection form is limited by a 'variable key', e.g. "localize" for multilingual variables, which needs to set to TRUE on respective variables.
  • There are two system variables for each realm, which store the list of available variables:
    • *_conf keeps the list of high-level variables; can be modified by the end-user via the settings ui; only exists if there actually is a settings ui (see above).
    • *_list keeps the list of low-level, actual variables names; this one is used as source of information about which form elements to annotate etc. It is automatically constructed from the *_conf variable, whenever that one is saved. There is a hook for other modules to modify it.
  • hook_form_alter() adds an infoblock at the top of every systems form which contains a realm-variable (as specified in respective *_list variables), and adds a set of links for switching the current realm for editing variable values.
  • The realm switcher is built automatically from the "keys" parameter in the realm info array; modules can create custom implementations by declaring a "realm switcher callback" in the array.

Comments

bforchhammer’s picture

StatusFileSize
new28.93 KB

Here is the patch.

Remaining ToDo's / Open Questions:

  • Fix system_theme_settings form: i18n_variable provides special treatment for theme settings -- I am not sure why or whether that needs to be generalized, and therefore haven't added it yet...
  • API Documentation: extend documentation for hook_variable_realm_info() with description of new keys (see variable_realm_admin_variable_realm_info_alter()). There are also new hooks which should be added to API docs.
  • Move hook_variable_realm_switch() into variable_realm, to allow other modules to act on realm switching. It is currently part of the realm admin module and only called when the realm-switcher block is used.
  • Possibly improve the "realm overview" page: I added only what was useful to me during development, but users may want to see something else (?)
  • Testing with i18n_variable module: I think most of it should work but I haven't tested it extensively... the theme settings form is one point on the list of things that might be broken now.
  • Fix string translation in hook_variable_realm_info_alter(); I am not sure how to properly translate strings in the info hook, because the results do not seem to be cached per language. (Separate issue?)

Follow up tasks for the i18n_variable module, if this patch gets added to the variable module:

  • Declare variable_realm_admin as new dependency
  • Add new variable realm information (currently in variable_realm_admin.variable.inc)
  • Remove i18n_variable_form_alter() and i18n_variable_module_implements_alter()
  • Remove admin code for variable selection; reuse variable_realm_admin_realm_settings() for admin/config/regional/i18n/variable
bforchhammer’s picture

Status: Active » Needs review

As per my previous comment, there are still a few bugs and remaining todos... However before I put more work into this I would love to get some feedback and possibly a code review :-)

The main goal for this patch from my perspective, is to simply replicate the functionality provided by the i18n_varibale module on a general level; without adding any new features.

jose reyero’s picture

Status: Needs review » Fixed
Issue tags: +Needs change record

This looks like a great start. Committed to variable module (added a dependency on variable_admin).

@bfordchammer,
You've been added to the commit list of variable module to maintain this new module.

Still I'd like to do some changes to this module, since I think some parts of it should be on variable realm. Let's keep the discussion on the variable_conf module to be more focused. #1559970: Battle plan / Progress

bforchhammer’s picture

Wonderful, thank you very much.

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

Anonymous’s picture

Issue summary: View changes

Minor