6

How do I programmatically create views in Drupal 7?

I would like to create a custom module that would output data as a view.

Is there any documentation on how to output views from a custom module?

4
  • Do you mean you want to execute an existing view (possibly with arguments), or that you want to define and create a new view from scratch in code?
    – Clive
    Mar 31, 2012 at 13:44
  • Clive, I would like to define a new view from scratch in code but to reuse the Views functionality instead of adding php code inside an existing view to avoid storing php code inside the drupal database.
    – LLub
    Mar 31, 2012 at 13:48
  • I found views api is described here: drupalcontrib.org/api/drupal/…
    – LLub
    Mar 31, 2012 at 14:01
  • 1
    this has some good pointers as well: views-help.doc.logrus.com/help/views/api-default-views
    – Jimajamma
    Mar 31, 2012 at 15:11

2 Answers 2

5

My first guess was to create a desired view using UI, export it and paste the generated code into own module. And I guess this is how admin_menu installs their admin views. You could install the module just for testing and see the contents of /admin_menu/admin_views/views_default/. At any rate, you would have to resort to writing a custom module and adhere to views' hooks syntax.

0
0

There is a very good step-by-step tutorial here: http://www.packtpub.com/article/creating-views-3-programmatically

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – mpdonadio
    Mar 19, 2017 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.