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 :)

CommentFileSizeAuthor
pager_make_count_query_public.patch425 bytesberdir

Comments

tobiasb’s picture

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

My 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)?

berdir’s picture

My only concern here is that getCountQuery() is specific to the PagerDefault implementation, and therefore not reliably present on a paged query

Correct, but isn't this exactly the same for setCountQuery() ?

Of course, different pagers already have different methods, so... OK, yeah, makes sense. :-)

No idea what extenders will evolve from contrib, maybe it will make sense to add something like isExtendedBy('PagerDefault') to D8?

Although can't you just as easily do $count = $query->countQuery() (which is the default anyway), modify that, and then $query->setCountQuery($count)?

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 :))

Crell’s picture

Hm, valid point. OK, RTBC it is. :-)

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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