in working on views-support for signup.module, i've run into some tricky problems with the view cache and default views from other modules. basically, if your views support is conditionally loaded in hook_menu() in your primary module, not stuffed into a totally separate signup_views.module or something, then it's really hard for your module to export default views and have that work automatically without the admin needing to manually clear their views cache.
i tried something fancy like this:
function views_form_alter($form_id, &$form) {
if ($form_id == 'profile_field_form') {
views_invalidate_cache();
}
if ($form_id == 'system_modules') {
$form['#submit']['views_system_modules_submit'] = array();
}
}
function views_system_modules_submit($form_id, $form_values) {
views_invalidate_cache();
drupal_set_message("Cleared views cache");
}
and even that didn't work, due to the timing of when things are loaded and run. :( so, this seems to be the only fool-proof solution:
function views_form_alter($form_id, &$form) {
if ($form_id == 'profile_field_form' || $form_id == 'system_modules') {
views_invalidate_cache();
}
}
in other words, *always* clear the views cache, even if you just view the admin/build/modules page. ;) works fine. i'm not sure if this is a major performance problem, but it certainly makes things work more correctly without manual effort on the part of the admin.
Comment | File | Size | Author |
---|---|---|---|
#1 | views_modules_page_clear_cache.patch_1.txt | 1.23 KB | dww |
views_modules_page_clear_cache.patch.txt | 641 bytes | dww |
Comments
Comment #1
dwwmerlin pointed out there was already code in hook_menu() trying to do this. however, since it was in $may_cache, it wasn't actually working. so, i removed that code block and moved the comment down to my change.
Comment #2
dwwbump. ;) in http://drupal.org/node/149921, it looks like merlin thought this patch had already landed... anyone care to RTBC?
Comment #3
moshe weitzman CreditAttribution: moshe weitzman commentedyup - looks good.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedCommited to -dev.
Comment #5
(not verified) CreditAttribution: commented