Return to Snippet

Revision: 61437
at December 13, 2012 00:47 by ihadgraft


Initial Code
/**
 * Implements hook_views_default_views().
 */
function mymodule_views_default_views() {
  $views = array();
  $path = drupal_get_path('module', 'mymodule') .'/views/default_views';
  foreach (glob($path .'/*.inc') as $filepath) {
    include($filepath);
    $views[$view->name] = $view;
  }
  return $views;
}

Initial URL


Initial Description
This snippet searches a subfolder at views/default_views for any files with a .inc extension.  Place exported views code in a file in views/default_views to have it picked up and included by the function.  This eliminates the mess of trying to keep several long exported views in a single file.

Initial Title
Implementing hook_views_default_views cleanly

Initial Tags


Initial Language
PHP