Problem/Motivation
Installing an installation profile might fail in some circumstances when for some reason webform_components()
is called before all modules where activated. For me this led to a hard to debug code where webform_component_defaults()
failed to give a result although the module defining the the component type’s function was already enabled.
Steps to reproduce
In one single script or request:
- Enable a module that defines a webform component type
- Call webform_components() → See the component is defined
- Enable a second module that defines a webform component type
- Call webform_components() → The second webform component is not defined.
Proposed resolution
Use drupal_static()
or the drupal_static_fast pattern.
Note that this only works if a patch for #1891356: D7: Reset drupal static caches when a module is enabled or disabled. is applied to Drupal core as well.
Remaining tasks
See patch / review status.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#3 | webform-3247737-drupal_static-3.patch | 560 bytes | torotil |
| |||
#2 | webform-3247737-drupal_static-2.patch | 1.82 KB | torotil |
|
Comments
Comment #2
torotil CreditAttribution: torotil at more onion commentedComment #3
torotil CreditAttribution: torotil at more onion commented… and without debug output ;-)
Comment #4
torotil CreditAttribution: torotil at more onion commentedComment #5
DamienMcKennaI wonder if this is what's causing one of our D7 sites to occasionally loose its webform components, or for some individual components to not show; both problems are resolved by clearing the caches.
Comment #6
DamienMcKennaI wonder if this is the same problem: #2427219: Webform disappears. Flushing the cache needed to make it reappear again
Comment #7
torotil CreditAttribution: torotil at more onion commentedIt could be. One explanation for what you describe would be if some module would call
webform_components()
before the full bootstrap is done and all modules are loaded. Then the incomplete (or empty) list of components would persist for the rest of the request.Comment #8
DamienMcKennaThat's what I'm thinking, though after the initial load the forms stay broken until the caches are cleared, which could be several days later. It doesn't happen very often, but in the past year it's happened at least twice, and each time a cache-clear fixed it.
We're going to test out your patch and will keep you posted.
Comment #9
Liam MorlandIs this patch tested and safe to apply even if #1891356: D7: Reset drupal static caches when a module is enabled or disabled. is not patched?
It would be great if someone would test to see if it fixes #2427219: Webform disappears. Flushing the cache needed to make it reappear again. If so, please post the fix there.
Comment #10
DamienMcKennaWe set it up on a large D7 site that gets a lot of Webform traffic that was running into occasional problems of the components disappearing. The problem would only happen once every few months so it's hard to replicate. I'll keep you posted.