I installed some default views with hook_views_default_view, and put the views files in
.../views/filename.view<code>. I then used this hook to bring them in:
<?php
function test_views_default_views() {
$files = file_scan_directory(drupal_get_path('module', 'test'). '/views', '.view');
foreach ($files as $absolute => $file) {
require $absolute;
if (isset($view)) {
$views[$file->name] = $view;
}
}
return $views;
}
?>
This seemed to work, but I had one view which I couldn't edit, export or clone: all the pages returned a 404. I could disable it, though, which confused me greatly.
Anyway, I think I've tracked this down to the %views_ui_cache loader: views_ui_cache_load > views_get_view > views_get_default_view > views_discover_default_views . The essential problem is that thew views cache returns a merged version of all the key/value arrays from, but each value i.e. <code>$view preserves its name attribute. Some aspects of Views use the key; others use $view->name.
That means that the following causes some pages to fail and some to succeed:
function test_views_default_views() {
$views[foo] = new $view;
$views[foo]->name = "bar";
/* ... */
return $views;
}
That means that hook_views_default_view requires an array of views, where each array key/value pair must have key == $value->name, or 404s start appearing. This isn't documented as far as I can see and there's no warning when you do this: the views happily appear at admin/build/view ; they just fail to appear at /clone , /edit or /export
Can anyone reproduce this? If so, can we have some sort of warning when this array is inconsistent according to what views.module needs?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 685656-63x_docs-1.patch | 1.22 KB | iamjon |
| #5 | 685656-63x_docs_php_0.patch | 1.02 KB | iamjon |
Comments
Comment #1
jp.stacey commentedWell, that formatting went all over the place.
Comment #2
merlinofchaos commentedYes, it is invalid to have the keys not match. At best this is a documentation issue for hook_views_default_views().
Comment #3
esmerel commentedComment #4
esmerel commentedComment #5
iamjon commentedDon't know if this still applies but if it does...
Comment #6
iamjon commentedAdding a new patch based on conversation with bojanz and dereine on irc
Comment #7
dawehnerLooks fine now.
Perhaps it could help to reference to an existing .views_default file like node.views_default.inc
Comment #8
esmerel commentedComment #9
merlinofchaos commentedCommitted to 6.x-3.x -- for 7.x since we're using CTools we probably want to do more, so leaving that for now.