Posted By

ihadgraft on 12/13/12


Tagged

drupal6 drupal7


Versions (?)

Implementing hook_views_default_views cleanly


 / Published in: PHP
 

This snippet searches a subfolder at views/defaultviews for any files with a .inc extension. Place exported views code in a file in views/defaultviews 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.

  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  

You need to login to post a comment.