I have just checked in a major change to the Views API. Details can be found in the advanced help under api.html (and the handlers and plugins) pages, but the short version is that all handlers and plugins are now separated into their own files in order to conserve memory and not loaded unneeded code. This required implementing an API versioning system, and the upshot of this is that a new hook must be implemented by all Views modules: hook_views_api(). Without the proper use of this hook, the *.views.inc files will not be included.

If your module includes its *.views.inc files itself or keeps its handlers in the .module file, this is wrong and will cause sites to crash.

Yay! You broke the Views API!

I was wondering when this was going to happen for Views 2. ;-)

I'm glad it happened before 6.x-2.0-official. I'm looking forward to the memory optimization! Every little optimization helps. And this sounds like a big optimization.

FYI, hooks_views_api() is documented here: http://views.doc.logrus.com/group__views__hooks.html And developers trying to figure out how to get NOT include *.views.inc in their module should look at hook_views_data().

Quick update instructions

It took me longer than it should have to figure this out, so I thought I'd post some quick and dirty upgrade instructions for anyone who has a working Views implementation that just needs to be updated for the new API (in other words, this is not about how Views2 works, just how to get from pre-API change to post-API change):

1) In MYMODULE.module add the api hook with a path to the place where the views files will be located:

<?php
function MYMODULE_views_api() {
return array(
 
'api' => 2,
 
'path' => drupal_get_path('module', MYMODULE) .'/includes',
);
?>

If you created any new subclasses for filters, arguments, etc., add a new hook in the file MYMODULE.views.inc called MYMODULE_views_handlers, with a path to the place where the individual handler file will be located, like:

<?php
function MYMODULE_views_handlers() {
  return array(
 
'info' => array(
   
'path' => drupal_get_path('module', MYMODULE) .'/includes',
    ),
 
'handlers' => array(
   
MYHANDLER => array(
    
'parent' => 'views_handler_filter_numeric',
     ),
    ),
  );
}
?>

Then go through any handlers or plugins you declare in the file MYMODULE.views.inc and remove them from MYMODULE.views.inc and move each one into its own file, named MYHANDLER.inc, using the path you named in the handler hook.

That should get things working, or mostly working. If you need more help than that, use the Advanced Help.

Each class in it's own .inc file

One other trick that totally got me tripped up is that each class needs to be in its own classname.inc file.

Thanks, I was banging my

Thanks, I was banging my head against the wall trying to figure this out;)

Bookings API

Yeah I had this issue when I was trying to use the BookingsAPI module and finally found it in the bottom of one of the advanced help pages.

We have got to help MerlinOfChaos write some documentation for Views 2.

Thanks

Thanks for writing this. It is straightforward and clear when set out like this. I strongly agree with dwees that better documentation is essential.

Post new comment

The content of this field is kept private and will not be shown publicly.