Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to replicate:
Install Views 3
Install CaseTracker
Try to edit via Views UI a view created from CaseTracker. Or access to a www.example.com/casetracker
I got this error:
Call to a member function init_pager() on a non-object in views/includes/view.inc on line 119
This is probably a bug in Views and not in CaseTracker, because the views should be editable even from the Views UI.
Also users cannot access to the view, they get the same fatal error.
Comment | File | Size | Author |
---|---|---|---|
#24 | views-698270-D6.patch | 4.17 KB | dagmar |
#24 | views-698270-D7.patch | 721 bytes | dagmar |
#23 | views-698270_1.patch | 3.67 KB | infojunkie |
#19 | views-698270.patch | 3.69 KB | dagmar |
#14 | 698270-ease-pager-override-settings.patch | 3.69 KB | dawehner |
Comments
Comment #1
dawehnerYou can also reproduce the error by using
Comment #2
dagmarThis issue is a consequence of several changes in the pager system for views 3:
See this links to trace how have been modified the set_items_per_page() function
http://drupalcode.org/viewvc/drupal/contributions/modules/views/includes...
http://drupalcode.org/viewvc/drupal/contributions/modules/views/includes...
http://drupalcode.org/viewvc/drupal/contributions/modules/views/plugins/...
In views 2, this function could be used to define if a views should use a pager or display all items. With the implementation of pluggable pagers, this behaviour was delegated in the plugins.
Case Tracker is calling to set_items_per_page()
And dereine php script also call directly to this function.
The problem is not really a bug of views, using Views UI, all is configured correctly to call set_items_per_page after $this->query is initialized.
Probably the best solution is to not call directly to set_items_per_page(), instead of that, modules should define 'none' as the pager plugin.
However this introduces a unnecessary backward compatibly between views 2 and 3.
So, I'm attaching a patch. What do you think about this solution?
Comment #3
dawehnerOne example:
Doesn't work as expected. I think we have to update $view->query->pager, too
Comment #4
dagmarNew patch
Comment #5
dawehnerI think we would need also it in $view->get_items_per_page $view->get_offset etc.
I think we should move up the initialization of the pager to $view::init_display. Then its definitive ready when it has to be there.
Additional this would later allow to attach settings to the query plugin, which is cool :)
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedI think I didn't do that because I wanted to retain the ability for the style plugin to change pagers. But maybe that's not really that big of a deal.
Comment #7
infojunkieLatest patch (#4) does not work for me as intended. I get Fatal error: Call to a member function get_plugin() on a non-object in /home/kratib/www/d6/sites/all/modules/views/plugins/views_plugin_query.inc on line 83.
My code looks like this:
and that's how it used to work in Views 2.x. Seems that we now need to call
$view->set_display($display_id);
before callingset_items_per_page
.Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedThis may be an API change you're going to have to live with.
Comment #10
merlinofchaos CreditAttribution: merlinofchaos commentedI think this patch ought to cover what we need. Can I get a test?
Comment #11
dawehnerMh
I corrected this.
The tests are running fine.
Manual testing worked fine too.
Comment #12
dawehnerThe problem was:
I changed this to
Comment #13
merlinofchaos CreditAttribution: merlinofchaos commentedI think that should be $this->query->use_pager()
That test is to see if the pager is actually paging. (For example, the simplest pager simply limits the number of records. It is a pager in the very strictest sense, and does not use the actual paging functionality).
Perhaps the function is misnamed?
Comment #14
dawehnerit should be $this->query->pager->use_pager
Comment #15
delykj CreditAttribution: delykj commentedThanks, dereine, you saved my day. #14 works perfectly for me.
Comment #16
dawehnerWas this a rtbc?
Comment #17
dagmar$view is visible at this point?
Or should be $this->current_page ?
Comment #18
dawehnerUpdate
Comment #19
dagmarOk, I tested the patch and works fine.
This file includes the fix reported in #17.
Comment #20
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted to 6.x and 7.x
Comment #22
dagmarI'm afraid this only was committed to DRUPAL-7--3, see http://drupal.org/cvs?file=/modules/views/plugins/views_plugin_query_def...
The patch still applies to DRUPAL-6--3.
Comment #23
infojunkieThe latest patch has a bug in that
set_offset
is called on the pager object, instead of the query object, resulting in a method not found error. The attached patch fixes this.Comment #24
dagmarNice catch. However, I think the bug is set_offset should be defined in views_plugin_pager in the same way that set_items_per_page is defined.
This patch is similar to #19 but includes a set_offset definition in views_plugin_pager.
I'm also attaching the D7 patch.
Comment #25
dawehnerI just review set_offset d7 patch. The rest of the d6 patch was already rtbc.
Kudos for creating a seperate d7 patch.
Comment #26
infojunkieLatest patch works for me.
Comment #27
merlinofchaos CreditAttribution: merlinofchaos commentedOk. Really, this one is committed this time.
Comment #29
cpotter CreditAttribution: cpotter commentedIt seems that this patch has not been applied to 3.0-alpha2