I'm writing a little module which should simplify creating a new view proccess for my site manager. What I want to do is to create a form, where the editor can fill some options (like title, path, some specific values for filtering etc) and then my code has to insert those options in my view template and import it to the database like a noraml view created via UI.

But as I understood, hook_views_default_value just loads the ready view item which is conteined in the module. But i want to create a new one each time with the same template. How can i do this?

Will be very appreciated for any advice.

  • This sounds very interesting Mar 19, 2015 at 2:22
  • You are asking how to programmatically create a view?
    – Brady
    Mar 19, 2015 at 7:57

1 Answer 1


I would suggest You to check views export functionality (admin/structure/views/view/name-of-some-view/export). There you should get the view object.

Then, copy this object to your form_submit function, replace desired values with form values and call $view->save() function. The view should be created (or updated, if such machine name exist.)


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.