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:

  1. Enable a module that defines a webform component type
  2. Call webform_components() → See the component is defined
  3. Enable a second module that defines a webform component type
  4. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil created an issue. See original summary.

torotil’s picture

Status: Active » Needs review
FileSize
1.82 KB
torotil’s picture

… and without debug output ;-)

torotil’s picture

Issue summary: View changes
DamienMcKenna’s picture

I 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.

DamienMcKenna’s picture

torotil’s picture

It 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.

DamienMcKenna’s picture

That'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.

Liam Morland’s picture

Is 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.

DamienMcKenna’s picture

We 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.