There is no reason for that method to be protected only.
Use case:
privatemsg.module defines quite complex query to list messages (message threads, actually). It also defines a custom count query and sets that with setCountQuery().
Now, privatemsg_filter.module extends that query with additional conditions based on tags, participants, ... It can do that on the on SelectQuery but there is no way to get the current count query().
Note that the public use of that function only makes sense in cases where a custom count query has been defined because in other cases, the changes wouldn't be saved and it wouldn't be necessary anyway, because the count query is rebuilt based on the actual query.
Patch is super simple :)
| Comment | File | Size | Author |
|---|---|---|---|
| pager_make_count_query_public.patch | 425 bytes | berdir |
Comments
Comment #1
tobiasbComment #2
Crell commentedMy only concern here is that getCountQuery() is specific to the PagerDefault implementation, and therefore not reliably present on a paged query. Of course, different pagers already have different methods, so... OK, yeah, makes sense. :-)
Although can't you just as easily do $count = $query->countQuery() (which is the default anyway), modify that, and then $query->setCountQuery($count)?
Comment #3
berdirCorrect, but isn't this exactly the same for setCountQuery() ?
No idea what extenders will evolve from contrib, maybe it will make sense to add something like isExtendedBy('PagerDefault') to D8?
No, because there is already a custom count query, countQuery() would just give me the default implementation again. I explicitly want the existing, custom count query.
Obviously, you need to be aware which query you are altering and what extenders it has. But I think there are valid use cases, and Privatemsg already has two of them. I worked around the first one, but there is no easy way to work around this (Except creating a custom extender that the property public through a different method :))
Comment #4
Crell commentedHm, valid point. OK, RTBC it is. :-)
Comment #5
dries commentedCommitted to CVS HEAD. Thanks.