I have a custom module which includes a view via hook_views_default_views().

After installing and enabling the module, admin/structure/views does not show the new view until I manually clear the Views cache (admin/structure/views/settings/advanced).

I am attempting to programatically clear the Views cache with hook_enable() in module.install.

/**
* Implements hook_enable().
*/
function mymodule_enable() {
  drupal_set_message(t('The MyModule module was successfully enabled.'), 'status');
  views_invalidate_cache();
}

I can see that hook_enable is fired because of drupal_set_message, but the Views cache isn't being cleared.

Any suggestions? Thanks.

Comments

More information... When I

More information...

When I clear all caches (admin/config/development/performance) the default view disappears from the list of views (admin/structure/views), and the view cannot be accessed through it's defined path. I can make things functional again by clearing the Views cache (admin/structure/views/settings/advanced).

Resolved - API documentation is incorrect

This was the first time I had implemented hook_views_default_views, so I read the API documentation carefully:

This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. MODULENAME.views.inc must be in the directory specified by the 'path' key returned by MODULENAME_views_api(), or the same directory as the .module file, if 'path' is unspecified.

This should read:

This hook should be placed in MODULENAME.views_default.inc and it will be auto-loaded. MODULENAME.views_default.inc must be in the directory specified by the 'path' key returned by MODULENAME_views_api(), or the same directory as the .module file, if 'path' is unspecified.

I tested and retested several times, starting with a clean system each time. You must place the hook in MODULENAME.views_default.inc or you will run into the same problem that I experienced.