2

We're writing some update functions for a custom module. This custom module provides some views:

/**
 * Implements hook_views_default_views().
 */
function mymodule_views_default_views() {
  $views_dir = drupal_get_path('module', 'mymodule') . '/views';
  $views_files = scandir($views_dir);
  $views = array();
  foreach ($views_files as $filename) {
    if (substr($filename, -4) == '.inc') {
      include_once $views_dir . '/' . $filename;
    }
  }
  return $views;
}

There are several .inc files from the view export ui and all those views are provided.

Now: some of those views should be updated. We usually just export and re-import them using the view ui (and override existing views). We wondered, how would this be possible programmatically? How to tell views which files to import again and override?

function mmodule_update_7001() {
  // what goes here?
}

Thanks for any ideas!

0

we ended up adding the following code inside the update_n function:

  $views_dir = drupal_get_path('module', 'mymodule') . '/views';
  $views_files = scandir($views_dir);
  $views = array();
  foreach ($views_files as $filename) {
    if (substr($filename, -4) == '.inc') {
      include_once $views_dir . '/' . $filename;
      if (isset($view) && is_object($view)) {
        views_save_view($view);
      }
    }
  }

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.