Closed (works as designed)
Project:
Strongarm
Version:
6.x-2.0
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Feb 2011 at 05:56 UTC
Updated:
14 Feb 2011 at 06:08 UTC
I have an ubercart variable I'd like to change depending on whether a user has a role or not. I tried doing the following but didn't work as I expected
$strongarm = new stdClass;
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'uc_ups_residential_quotes';
$strongarm->value = '1';
if (in_array('wholesaler', $user->roles)) {
$strongarm->value = '0';
}
$strongarms['uc_ups_residential_quotes'] = $strongarm;
Is this possible? I'm not familiar with how ctools exportables works code wise, maybe it is a ctools limitation? I'd be glad to supply a patch if it's fixable in strongarm.
Comments
Comment #1
Grayside commentedStrongarm values are cached, which means you can't really modify them per page load. However, if you look at strongarm_init() and strongarm_set_conf(), you can see that it's actually really easy to modify what variables are available during a page load. If you modify the global $conf variable after strongarm does it's thing, you can change the variables however you like.
I would mark this as a won't fix, since clearly breaking Strongarm's caching mechanism is not an option, but I suppose it's possible Strongarm could create a new hook. The maintainers might well prefer to see a more general Variable management module take that on, like http://drupal.org/project/variable.
Comment #2
rocketeerbkw commentedI'm certainly not in favor of breaking any kind of cache. I looks like modifying $conf in my own hook_init() is going to work just fine for what I need.
I'm not sure adding a new hook to strongarm is a solution since ubercart was using variable_get() and that was what I was trying to intercept. It seems that variable_get() would have to invoke a hook to get around modifying $conf directly.
Unless the maintainers want to have some kind of discussion on this topic the issue can be closed.
Thanks Grayside +1
Comment #3
Grayside commentedvariable_get() is a wrapper around pulling from $conf. Therefore, as long as Ubercart's variable_get() call happens after you modify the variable, it does not matter how it is changed. However, given that this would be a scope shift for Strongarm, it's safe to assume that if you have a solution, this is fixed.
Comment #4
Grayside commentedBetter status :/