Providing default view with your module.

20 06 2009

Recently we released Twitter Search Feeds module. I wanted to provide default view with this module. To do that I did following steps.

1. Implemeted hook_views_api function like this.
function modulename_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'modulename'),
);
}

2. Exported the view that I wanted to keep in my module and stored the exported content in a file with the name MODULENAME.views.inc like this.

function modulename_views_default_views() {
$views = array();
// Start copy and paste of Export tab output.
// End copy and paste of Export tab output.
// Add view to list of views to provide.
$views[$view->name] = $view;
// ...Repeat all of the above for each view the module should provide.
// At the end, return array of default views.
return $views;
}

That’s it, when enable the module, this view will appear in the views list.

In the first step hook_views_api function is telling that we have a default view which is there in the module path.

In the second step we implemented hook_views_default_view with view structure. This function return the array of views. This method is for the views2/drupal6.

There is a very good article explaining this Speed Up and Version Your Views

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: