How to disable views programmatically when the offering module is disabled
I came across this case recently. I maintain the tiny module - uiplog which logs the IP address, user id and login timestamp of Drupal site users on login event. The logged details are exposed in a page using views module
hook_view_data(). When the uiplog module is disabled the views offered by the module remains active and when the views page is accessed it throws PHP notices and warnings. I was wondering to fix it. After a bit of research I came up with the following snippet to disble views on disabling the module using
The code works as follow, the function
uiplog_disable() which is a hook; triggered when the uiplog module is attempted to disable. Using
module_invoke() call all the default views defined in the uiplog is pulled as an array to
$default_views. For each default view in uiplog the status is set to false and views cache is reset.