Convert your views into a custom module I'm using Views 3 on Drupal 6.

A while back I read an article how you can take your views and put it in your "custom' module folder (granted you've set this up for custom theme functions). I haven't had much need for it lately, but recently I've been doing a lot of work for a client that has needed a bunch of reworking of their Views and CSS related to them. This has turned into a bit of a nightmare trying to make sure that they then take my exported views from my development server to their server and import them correctly (sometimes they rename them, sometimes settings are not exported for whatever reason, etc). 

A while back a read an article about converting your views into modules and it seemed pretty straight forward, but now I can't find it. Could anyone point me in the right direction? All I could find is a 50 minute long video tutorial, and I would rather just have an article I can skim. 

Thanks!  

EDIT: 

The below link seems like it should work, but I'm not sure what I'm doing wrong. It just dumps all the views export code at the top of the page. What I did: 

Put this into my "sitetheme.module" 

function sitetheme_views_api() {
   return array(
      'api' =&gt; 3,
  );
}


Created this separate file named "sitetheme.views_default.inc". Which I put in this code: 

/**
* Implementation of hook_views_default_views().
 **/
function sitetheme_views_default_views(){
  $files = file_scan_directory(drupal_get_path('module', 'sitetheme'). '/views',     '.view');
  foreach ($files as $filepath =&gt; $file) {
  require $filepath;
  if (isset($view)) {
 $views[$view-&gt;name] = $view;
  }
 }
  return $views;
} 


Then I made a new folder in my sitetheme module called "views", took the export code and saved it something like "myexportview.view" and saved it under the "views" folder. 

Then when I upload these files to the client server it just dumps all the code at the top of the admin/build/views page. 

Any idea what I did wrong? I seem to be following the directions exactly but I'm not sure what I'm missing... 



It appears that I had to put a &lt;?php at the top of the myview.view export file. However, now Drush doesn't work... I get a fatal error from Drush when I try to clear the cache:


  Fatal error: __clone method called on non-object in /Users/mycomputer/Sites/mysite/htdocs/includes/common.inc on line 1733
When the Bulk Export module (part of the Chaos Tools Suite module) is enabled, it exposes a page (admin/structure/bulk-export) where views can be exported.

What you need to do is selecting the views you want to export, enter the short name of the module that will contain the views, and click on the "Export" button.



The page that will appear next contains three text area fields (&lt;module name&gt; is the short name you entered in the previous page):


One is for the content to place in &lt;module name&gt;.info
The second is the content to place in &lt;module name&gt;.module
The last is the content to place in &lt;module name&gt;.views_default.inc


The differences I can see between the code the module tells me to use, and the one you are showing are:


The implementation of hook_views_api() is the following.

/**
 * Implements hook_views_api().
 */
function sitetheme_views_api($module, $api) {
  if ($module == 'views' &amp;&amp; $api == 'views_default') {
    return array('version' =&gt; 2);
  }
}

The implementation of hook_views_default_views() is the following.

/**
 * Implements hook_views_default_views().
 */
function sitetheme_views_default_views() {
  $views = array();

  $view = new view();

  // …

  return $views;
}



$views is an array of objects of the view class.