1

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?

1
  • I had a similar question and found an answer at Sivaji's Drupal Site - sivaji.drupalgardens.com/… Plugging my view name in to lines 5 and 6 worked for me in a hook_update_n(). Apr 2, 2013 at 18:19

1 Answer 1

2

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();
    }
}
1
  • this is not an answer. question is about removing of views display
    – milkovsky
    Jul 24, 2014 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.