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?

Comments

jp.stacey’s picture

Well, that formatting went all over the place.

merlinofchaos’s picture

Yes, it is invalid to have the keys not match. At best this is a documentation issue for hook_views_default_views().

esmerel’s picture

Component: Code » Documentation
esmerel’s picture

Assigned: Unassigned » esmerel
iamjon’s picture

Version: 6.x-2.6 » 6.x-3.x-dev
Category: bug » task
Status: Active » Needs review
StatusFileSize
new1.02 KB

Don't know if this still applies but if it does...

iamjon’s picture

StatusFileSize
new1.22 KB

Adding a new patch based on conversation with bojanz and dereine on irc

dawehner’s picture

Looks fine now.

Perhaps it could help to reference to an existing .views_default file like node.views_default.inc

esmerel’s picture

Status: Needs review » Reviewed & tested by the community
merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 6.x-3.x -- for 7.x since we're using CTools we probably want to do more, so leaving that for now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.