So the default behavior of the module is to create an export/views directory filled with .view files that are 'text'-only.

I wrote a function to loop through this directory and uses file_read_contents and eval :( to create the php objects and return them through hook_default_views(). Is there a way we can close this gap so a call to drush views export would be all that is needed?

CommentFileSizeAuthor
#5 drush_views_671062-5.patch2.38 KBxjm

Comments

sethcohn’s picture

actually, I'd prefer this be 'fixed' with:

1) Custom filename extension (rather than .view) would be good, optionally.
2) (optionally) Add a php start tag to the beginning, and "$views[$view->name] = $view;" to the end of the file

The above additions would mean I could export right into my custom views export directory(ies) (there is a path setting already) and just use my already existing file reading code for hook_views_default_views (which is stock code used by dozens of modules which already do views including in this way)...

This would help support best practices for views rollout in a production environment.

miche’s picture

+1 to sethcohn's request!

anders.fajerson’s picture

xjm’s picture

+1, this would be very useful.

xjm’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new2.38 KB

Attached patch is against 6.x-3.x-dev. It adds an --as-include option to to the drush vwex command. This option will export the file as a .inc in a format that hook_views_default_views() can load, as described in #1.

Works great for me!

(By default, without the --as-include flag, files will still be exported in the .view format that drush_views imports.)

xjm’s picture

For the uninitiated, here's an example of how to include these files after you export them using the patch. I have a teensy module I made called views_cache.module that contains only the following hook:

function views_cache_views_default_views() {
  $views = array();
  $path = drupal_get_path('module','views_cache') . "/files";
  $files = drupal_system_listing("\.inc$", $path, 'name', 0);
  drupal_set_message(print_r($files,true));
  foreach ($files as $file) {
    include_once($file->filename);
  }

  return $views;
}

So, I would run the following command to export the "view_name" view to my module's directory, and would see the following output:

$ drush vwex --target-path=sites/all/modules/views_cache/files --as-include view_name
Exporting 1 views to directory sites/all/modules/views_cache/files/: [ok]
- Exporting view view_name to file                                   [ok]
sites/all/modules/views_cache/files/view_name.inc.
Done.                                                                [ok]
$ _
pescetti’s picture

Thanks for comments and code, but I consider this issue to depend on #626876: New export syntax: allow export by tag, export to stdout, function header: once that one is closed, it could fulfill this need too; your patch could possibly be reused there as well. Anyway, #626876: New export syntax: allow export by tag, export to stdout, function header will be closed before this one and then it will be possible to better evaluate this issue.

luckysmack’s picture

subscribe

jsenich’s picture

Subscribe.

larowlan’s picture

+1

pescetti’s picture

Assigned: Unassigned » pescetti
Status: Needs review » Fixed

Thanks, this functionality is now committed to the 3.x branch, with a more general syntax than the one outlined here.

If you want to export, say, the two views "og_members" and "og_unread", you will use something like:

drush vwex og_members,og_unread --output=includes

to produce a file-based export as individual .inc PHP files that can be included by hook_views_default_views().

The old, still default, functionality will use something like:

drush vwex og_members,og_unread --output=files

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.