hook_views_api makes it possible to define a template path for your module where you can store views templates. When you have specified this key views automatically uses the template files for the views. Features as it stands does not include this in the version of hook_views_api it adds to the features.inc file in the features module. It would be a nice feature to include this either if the folder 'views-templates' exists in the module directory or maybe if a variable were specified in the info file e.g. features[views_template_path] = "theme/views-templates"
An example hook_views_api implementation is:
/**
* Implements hook_views_api().
*/
function mymodule_views_api() {
list($module, $api) = func_get_args();
if ($module == "views" && $api == "views_default") {
return array(
"version" => "3.0",
"template path" => drupal_get_path('module', 'mymodule') . "/views-templates",
);
}
}
Comments
Comment #1
njcheng commentedThis would be incredibly useful.
Comment #2
hefox commentedAn alternate solution to this is when adding suggestion for these, check if the suggestion is already added to this feature, and if it's not, see if the hook is already implemented. If it is, don't autocreate this. This would allow people to do the hook in the .module and construct it any way they want.
I've done that before with features; it's like one or two line change, if I recall correctly.
Comment #3
njcheng commented@hefox, thanks so much for the comment. Can you be a bit more specific or include an example of how to do this?
Comment #4
hefox commentedThe views_api being included is suggested in the hook_features_export of views (which is made via ctools in d7). That hook is passed the module name. Using that module name, can look up and see if that views_api component is currently part of export (features component map function may have that info)? If it's not included, but function_exists for $module_name _views_api, then don't suggest it.
Comment #5
jantimon commentedFor now I am using an ugly workaround for this:
features.ctools.inc line 68
This enables me to implement a plugin_api_overwrite method and implement
custom views handlers.
Comment #6
johnennew commentedHere is another workaround which just involves hooks to tell features not to include the hook_views_api function in a features module. You can then specify the function yourself in the features module .module file.
The features hook is:
Some more detailed instructions can be found here:
http://deeson-online.co.uk/labs/views-templates-features-module
Comment #7
njcheng commented@ceng, thanks so much for this work-around. Totally worked.
Comment #8
milesw commentedFor those arriving at this thread, a commenter on the blog post in #6 pointed out there is now a
hook_views_api_alter()available.This issue is supposedly fixed in Features already.
Comment #9
mpotter commentedComment #10
ice5nake commentedPorting hook_views_api_alter() to 6.x?
Comment #11
kenorb commentedExample: