Skip to content

Instantly share code, notes, and snippets.

@jpstacey
Created June 11, 2010 11:46
Show Gist options
  • Save jpstacey/434393 to your computer and use it in GitHub Desktop.
Save jpstacey/434393 to your computer and use it in GitHub Desktop.
Clean Drupal hook_views_Default_views
<?php
/**
* Implementation of hook_views_default_views
*/
function example_views_default_views() {
return example_default_views_from_files();
}
/**
* Helper function for default views - get from files in a subdirectory
*/
function example_default_views_from_files($module = 'example', $subdir = 'views') {
$files = file_scan_directory(drupal_get_path('module', $module). "/$subdir", '.view');
foreach ($files as $absolute => $file) {
require $absolute;
if (isset($view)) {
$views[$file->name] = $view;
}
if ($views[$file->name]->name != $file->name) {
drupal_set_message(t('The view @n has inconsistent naming and might not be overrideable in the views UI',
array('@n' => $file->name)), 'warning');
}
}
return $views;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment