• Category Archives Drupal
  • How to import (revert) views in Drupal 7.x

    Developing web applications using CMS like Drupal may be chalanging when there are more than one developer working on the same project. Source code is managed easily with Git (or other VCS), but the database content must be treated with care. Either you go for a relay baton method: One developer updating the database at the time and all other must get new dumps after the update, or you can export / import features stored in the database.

    I wanted to try the latter with Drupal Views, and could not find any documentation that worked out-of-the-box with my project so here is what I ended up with:

    Create a new module
    See Creating modules – a tutorial: Drupal 7.x

    Export view(s)
    Export whatever views you want to be able to import (revert). From the views list (admin/structure/views) you should be able to select “Export” on the views you want to export.
    This will display PHP code in a textarea. You should copy the contents and paste it in a file, say named view.my_exported_view.inc.
    Remember to add “<?php” on the first line.

    My example files
    Here is my modules/viewsimport/viewsimport.info file:

    Here is my modules/viewsimport/viewsimport.module file:

    Here is my modules/viewsimport/viewsimport.views_default.inc:

    Some of the articles I stumbled over: