Implementing hook_views_default_views cleanly


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. /**
  2.  * Implements hook_views_default_views().
  3.  */
  4. function mymodule_views_default_views() {
  5. $views = array();
  6. $path = drupal_get_path('module', 'mymodule') .'/views/default_views';
  7. foreach (glob($path .'/*.inc') as $filepath) {
  8. include($filepath);
  9. $views[$view->name] = $view;
  10. }
  11. return $views;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.