Created
November 25, 2011 23:08
-
-
Save joshuapowell/1394630 to your computer and use it in GitHub Desktop.
Drupal 7 & Views 3 capable dynamically loading views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Views object for the 'My Custom View' view | |
* | |
* This file would be saved inside of the previously created | |
* 'views' directory inside of the MYMODULE module directory. | |
*/ | |
$view = new view; | |
$view->name = 'my_custom_view'; | |
$view->description = 'A description of my custom view'; | |
$view->tag = 'default'; | |
$view->base_table = 'node'; | |
$view->human_name = 'My Custom View'; | |
$view->core = 7; | |
$view->api_version = 3; | |
$view->disabled = TRUE; | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "MY MODULE" | |
description = "Custom Views specific to a website" | |
package = "MY WEBSITE" | |
core = 7.x | |
dependencies[] = views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Custom views specific to a website | |
*/ | |
/** | |
* Implementation of hook_views_api(). | |
*/ | |
function MYMODULE_views_api() { | |
return array( | |
'api' => 3 | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Load multiple views from a folder | |
*/ | |
/** | |
* Implementation of hook_views_default_views(). | |
* | |
* Create a directory named 'views' inside of your | |
* module directory (e.g., MYMODULE) | |
* | |
* Export each view and save file with an opening php | |
* delimiter at the beginning of the file, then paste | |
* in your exported Views object, and finally save your | |
* file with an .inc extension inside the newly created | |
* 'views' directory. | |
*/ | |
function MYMODULE_views_default_views() { | |
$views = array(); | |
$path = drupal_get_path('module', 'MYMODULE') . '/views'; | |
$files = drupal_system_listing("/\.inc$/", $path, 'name', 0); | |
foreach($files as $file) { | |
include $file->uri; | |
$views[$view->name] = $view; | |
} | |
return $views; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment