Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Strongarm is great for exporting configuration variables, but sometimes the values change between environments. For example the admin_user_role changes depending on the order the roles were created in the different environments. In the case of WF I want to be able to set the default environment, but exporting an environment id isn't very useful, I want to export the UUID for that environment.
2 alter hooks would provide the functionality I've outlined above, one for importing variables and the other when exporting them.
Patch coming right up.
Comment | File | Size | Author |
---|---|---|---|
#11 | interpatch.txt | 244 bytes | fengtan |
#11 | strongarm-2076543-import-export-value-alter-hooks-11.patch | 2.64 KB | fengtan |
Comments
Comment #1
skwashd CreditAttribution: skwashd commentedHere is the patch that implements this functionality.
Comment #2
timaholt CreditAttribution: timaholt commentedI have reviewed and tested this. The code looks good, and implementing this hook in a custom module worked once I applied the patch.
Comment #3
timaholt CreditAttribution: timaholt commentedIt should be noted that using this in conjunction with Features requires Features 7.x-2.0-rc3 or greater.
Comment #4
danithaca CreditAttribution: danithaca commentedDoes these 2 hooks overlap with hook_strongarm_alter()? See #1594850: Override variable value when adding to feature.
Comment #5
danithaca CreditAttribution: danithaca commentedI have also reviewed and tested the code, and it works on 7.x-2.0 release. The patch is not likely to introduce regression errors because it only adds 2 extra hooks and doesn't change any existing code at all. It might introduce errors related to caching, but if people are using the 2 hooks, then they are responsible to take the risk. I'd suggest add this patch to 7.x-2.x release.
As to my previous comment about hook_strongarm_alter(), note that hook_strongarm_alter() is only called by features_get_defaults(). Therefore, it's only able to alter the value saved in *.strongarm.inc, not the value saved in the database. There's no way to alter anything in variable_features_export_render() so there's no way to alter the value saved in the database when exporting to *.strongarm.inc. I also searched all drupal_alter() in both the Features module and the CTools module, and can't find any hook available to alter the value when exporting variables into *.strongarm.inc. So this patch seems to be the only option.
Comment #6
barraponto CreditAttribution: barraponto commentedIf I check the feature status, it will mark the values altered in the import hooks as overriden. Since the changes are in code, they could just be reported as default, right?
Comment #7
skwashd CreditAttribution: skwashd at Dave Hall Consulting for Pfizer, Inc. commented@barraponto I know it has been some time since I looked at this. I have tried to replicate the problem you describe locally and couldn't replicate it. I was using variables that referenced entities with uuids.
Can you provide an example that I can test with?
Comment #8
karolinam CreditAttribution: karolinam commentedI also tested the patch with Strongarm 7.x-2.0 release. I implemented the 2 hooks in a custom module and it works. Strongarm feature component is in default state.
Comment #9
skwashd CreditAttribution: skwashd at Dave Hall Consulting for Pfizer, Inc. commented@karolinam if you're happy with the patch please mark it as RTBC.
Comment #10
karolinam CreditAttribution: karolinam commentedComment #11
fengtanWorks like a charm, thanks @skwashd.
Attached is a new patch with a trivial update on the documentation (see interpatch).