function tripal_disable_view

2.x tripal_views.api.inc tripal_disable_view($view_name, $redirect_link = FALSE)

Programatically disable view.

This should be used in a hook_menu definition as the callback to provide a link to disable the view (first example). It can also be called directly if needed (second example).

// Create a URL that when the user navigates there, a given view will be disabled.
// You will still need to provide a link to this menu item somewhere appropriate.
function mymodule_menu() {
 $items = array();

 // Create one of these for each of your default views
 $items['admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/disable'] = array(
   'title' => 'Disable <VIEW-HUMAN-READABLE-NAME>',
   'page callback' => 'tripal_disable_view',
   'page arguments' => array('<VIEW-MACHINE-NAME>', '<PATH-TO-REDIRECT-TO-AFTERWARDS>'),
   'access arguments' => array('<YOUR-PERMISSION-KEY>'),
   'type' => MENU_CALLBACK,
 );

 return $items;
}

// Call this function directly to disable a view
// The example shows disabling your own default view when your module is uninstalled
function mymodule_uninstall() {

 $view_name = '<VIEW-MACHINE-NAME>';
 tripal_disable_view($view_name);

}

Parameters

$view_name: The machine-name of the view to be enabled

$redirect_link: The path to redirect to. FALSE if no redirect needed

Related topics

18 calls to tripal_disable_view()
tripal_analysis_disable in tripal_analysis/tripal_analysis.install
Implements hook_disable(). Disable default views when module is disabled
tripal_bulk_loader_disable in tripal_bulk_loader/tripal_bulk_loader.install
Implements hook_disable(). Disable default views when module is disabled
tripal_contact_disable in tripal_contact/tripal_contact.install
Implements hook_disable(). Disable default views when module is disabled
tripal_cv_disable in tripal_cv/tripal_cv.install
Implements hook_disable(). Disable default views when module is disabled
tripal_db_disable in tripal_db/tripal_db.install
Implements hook_disable(). Disable default views when module is disabled

... See full list

1 string reference to 'tripal_disable_view'

File

tripal_views/api/tripal_views.api.inc, line 279
API functions for Tripal Views Integration

Code

function tripal_disable_view($view_name, $redirect_link = FALSE) {

  $status = variable_get('views_defaults', array());
  if (isset($status[$view_name])) {
    $status[$view_name] = TRUE;
    variable_set('views_defaults', $status);
    drupal_set_message("Disabled $view_name");
  }
  else {
    drupal_set_message("Unable to find a view by the name of '$view_name'. Unable to disable this view.", 'error');
  }
  if ($redirect_link) {
    drupal_goto($redirect_link);
  }
}