Closed (fixed)
Project:
Views (for Drupal 7)
Version:
5.x-1.6
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Dec 2008 at 07:08 UTC
Updated:
8 Jan 2010 at 23:02 UTC
I exported a custom view for my module. I want to re-import it programmatically inside my module installer.
I tried drupal_execute('views_ui_import_page', $form_state); it didn't work. From the view admin GUI, I noticed that a view also needs be saved after it is imported.
Any help is greatly appreciated.
thx!
Comments
Comment #1
merlinofchaos commentedPlease read the documentation, particularly the page entitled "Using default views in your module" before posting support requests.
Comment #2
jako0013 commentedHow about in Drupal 5? It's not so obvious, even with the Drupal 6 documentation.
Comment #3
jako0013 commentedSorry, upon further reading I think I get it, but I would like to know if Views for Drupal 5 contains the same functionality as described on http://views-help.doc.logrus.com/help/views/api-default-views. Thank you.
Comment #4
merlinofchaos commentedDrupal 5 also supports default views. That documentation is on drupal.org under http://drupal.org/handbook/modules/views/api
Comment #6
tylerwalts commentedI see that this thread is closed, so please help me to redirect this post if it is in the wrong place...
This applies to Drupal 6.x
My goal was to programatically import a set of views, and then automatically enable them and display the block views on a page. I too struggled with getting the out-of-the-box views api to automatically load a view export saved as a file. I ended up using a bash script in the end, with help from drush and views_import module (I only need to do this once, during a site migration script, so for me I did not care about using a module.) If you must have this in a module, then a similar approach can be taken by substituting the php parts where bash/drush is used. Here is the basic script:
This code just does a single view, and it assumes that the view has a block display set up. You could do a whole folder of view exports at once, and then either copy/paste the eval and sql lines, or turn them into big statements that eval/execute multiple array items / db rows. It does not matter what you name the view export file names, as long as they only contain the copied code from the export textarea. I named mine *.view just to be clear.
Cheers,
- Tyler
Comment #7
westbywest commented@merlinofchaos
Default views are not helpful if you need to override a default view defined by a contributed module. Your module can't override another module's default view with its own default view.
In this instance, you do have to define an overridden view in the DB, and being able to do so programmatically becomes very useful.