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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dww’s picture

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

dww’s picture

bump. ;) in http://drupal.org/node/149921, it looks like merlin thought this patch had already landed... anyone care to RTBC?

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

yup - looks good.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Commited to -dev.

Anonymous’s picture

Status: Fixed » Closed (fixed)