Skip to content

Instantly share code, notes, and snippets.

@henrytran9x
Created March 13, 2015 17:07
Show Gist options
  • Save henrytran9x/e50ebd7d58a63eab5f42 to your computer and use it in GitHub Desktop.
Save henrytran9x/e50ebd7d58a63eab5f42 to your computer and use it in GitHub Desktop.
Creating views view in your module is really simple.
<?php
// 1.
// Create your view the regular way.
// 2.
// Define your views api version and path for files that include views hooks.
/**
* Implementation of hook_views_api().
*/
function HOOK_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'HOOK')
);
}
// 3.
// Views export creates code that you have to paste in this function.
/**
* Implementation of hook_views_default_views().
*/
function HOOK_views_default_views() {
// Paste code form views export.
$views[$view->name] = $view;
return $views;
}
// 4.
// Delete your view and clear all caches, view from your code should appear. When you change the view don't forget to add the changes to code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment