How to disable views programmatically when the offering module is disabled


Here is a snippet of code you would put in mymodule.install

/**
* Disable workbench views
*/
function mymodule_update_7001() {
// a list of views (their view name) I want to disable
$viewnames = array(
‘workbench_current_user’,
‘workbench_edited’,
);
// grab list of views that are already disabled
$views_status = variable_get(‘views_defaults’, array());
// add our views to be disabled to the list
foreach ($viewnames as $key => $viewname) {
$views_status[$viewname] = TRUE;
}
// reset the variable with the new list
variable_set(‘views_defaults’, $views_status);
// empty cache now
if (function_exists(‘views_invalidate_cache’)) {
views_invalidate_cache();
}
}

Advertisements

  1. Leave a comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: