I'm using the Patterns module to automate the configuration of NAT-ng settings for different node types using a custom NAT-ng pattern (http://github.com/hiddentao/patterns2).
I'm finding that when I have multiple NAT-ng patterns running one after another in a single web call only the pattern that gets run at the end has any effect. The changes made by the previous patterns don't get saved. Since Patterns uses the Form API to update components I tracked the problem down to the call made from nat_ng_settings_form() to the _nat_ng_variable_get() method:
function _nat_ng_variable_get($name = NULL) {
static $variables = array();
if (empty($variables)) {
$defaults = array(
'types' => array(),
'body' => array(),
'delete' => array(),
'delete_node' => array(),
'related' => array(),
'node_links' => array()
);
$variables = variable_get('nat_ng_config', array());
$variables = array_merge($defaults, $variables);
}
return $name ? $variables[$name] : $variables;
}
Once the nat_ng_config variable is loaded using variable_get() it is cached within this function. My patterns essentially build and submit the settings form multiple times within a single web call and thus, only the initial cached value keeps getting saved. To work around this I propose introducing a backwards-compatible change to this method as such:
function _nat_ng_variable_get($name = NULL, $reset = FALSE) {
static $variables = array();
if ($reset || empty($variables)) {
$defaults = array(
'types' => array(),
'body' => array(),
'delete' => array(),
'delete_node' => array(),
'related' => array(),
'node_links' => array()
);
$variables = variable_get('nat_ng_config', array());
$variables = array_merge($defaults, $variables);
}
return $name ? $variables[$name] : $variables;
}
And in nat_ng_settings_form() the call to the method will now be:
$nat_ng_config = _nat_ng_variable_get(NULL,TRUE);
This way the NAT-ng settings from will always show the latest saved version of the nat_ng_config variable.
Patch attached.
| Comment | File | Size | Author |
|---|---|---|---|
| nat_ng_variable.patch | 1.68 KB | hiddentao |
Comments
Comment #1
anantagati commentedLooks acceptable. I will test it and if everything will be ok, I will commit it.
Comment #2
anantagati commentedComment #3
anantagati commentedIt is committed to 6.x-1.x-dev.
Comment #4
hiddentao commentedThanks.