Any idea how can I remove or delete Views display programmatically?
I have a Views that has 5 displays and I want to delete one of them. For the sake of avoiding manual intervention I want to do it automatically via code. Is there a way to do that?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityAny idea how can I remove or delete Views display programmatically?
I have a Views that has 5 displays and I want to delete one of them. For the sake of avoiding manual intervention I want to do it automatically via code. Is there a way to do that?
Here is an example you would put in mymodule.install
/**
* Disable workbench views
*/
function mymodule_update_7001() {
// an array of views (their view name) I want to disable
$viewnames = array(
'workbench_current_user',
'workbench_edited',
'workbench_moderation',
'workbench_recent_content',
);
// grab the array 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();
}
}