Save actions settings by locale
flevour - November 30, 2008 - 00:34
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | system.module |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Description
In the current implementation actions parameters are being saved as a serialized array in the parameters field of the actions table.
It would be nice if there could be different settings for each language installed in the installation. For example, if I wanted a "Send email" action to be localized, I currently would have to create N separate actions with content translated to each of the N installed languages.
The attached patch saves and loads data using an array keyed by language.
This of course would break current configuration and could easily be fixed: an upgrade script could resave current settings into the new format, moving current $params to $params[$language->$language].
| Attachment | Size |
|---|---|
| localize.actions.settings.patch | 1.96 KB |
| Testbed results | ||
|---|---|---|
| localize.actions.settings.patch | failed | Failed: Failed to apply patch. a href=http://testing.drupal.org/pifr/file/1/localize.actions.settings.patchDetailed results/a |

#1
Updated patch to 7.x.
#2
With latest patch, if you want to edit a specific language for an action, you just switch language. A problem comes up when you switch to a language for which no translated settings have been previously entered. Currently the form would be empty, while I think it should be filled with settings from another language to help translation.
The issue is how to pick up the "right" language to load default settings from. In fact, you can't always assume settings for the default site language have been entered first (or yes?).
I suggest trying this pseudo-code:
* when trying to load settings in language $lang for an action
* load settings $settings
* if $settings[$lang] is empty, try to load $settings[site_default_lang]. If this is empty too, load the first not empty language you find.
#3
Updated patch based on the reasoning of previous comment. It implements a clever settings loading to avoid empty settings forms for existing actions.
Still missing an upgrade path for existing actions, but I'd leave that for when I get confirmation this patch is good to go in.
Anyway it'd be something like this:
<?php$result = db_query("SELECT * FROM actions WHERE aid >= 1");
$default_language = language_default('language');
while($row = db_fetch_object($result)) {
$params[$default_language] = unserialize($row->parameters);
db_query("UPDATE actions SET parameters = '%s' WHERE aid = %d", serialize($params), $row->aid);
}
?>
#4
As I work more through the code, I realize the real logic that needs to be changed is in includes/actions.inc. The whole patch here can be thrown away. I will currently postpone this issue until the #342983: Improve handling of $action object throughout Drupal core gets worked out.