20 May 2013

Creating views view in your module is really simple.

Source code viewer
  1. // 1.
  2. // Create your view the regular way.
  3.  
  4. // 2.
  5. // Define your views api version and path for files that include views hooks.
  6. /**
  7. * Implementation of hook_views_api().
  8. */
  9. function HOOK_views_api() {
  10. return array(
  11. 'api' => 3.0,
  12. 'path' => drupal_get_path('module', 'HOOK')
  13. );
  14. }
  15.  
  16. // 3.
  17. // Views export creates code that you have to paste in this function.
  18. /**
  19.  * Implementation of hook_views_default_views().
  20.  */
  21. function HOOK_views_default_views() {
  22.  
  23. // Paste code form views export.
  24.  
  25. $views[$view->name] = $view;
  26. return $views;
  27. }
  28.  
  29. // 4.
  30. // Delete your view and clear all caches, view from your code should appear. When you change the view don't forget to add the changes to code.
Programming Language: PHP