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?

  • 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(). – Sean Hanford Apr 2 '13 at 18:19
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();
    }
}
  • this is not an answer. question is about removing of views display – milkovsky Jul 24 '14 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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