Pagelist filter() deprecation

What is the replacement for this deprecated method, or how do we go about filtering like this now? I can’t seem to find anything appropriate. Looking at the v9rc3 page list block controller we’re still doing this:

$this->list->filter(‘cvName’, ‘’, ‘!=’);

leaving me unsure at the moment…

1 Like

@enlil the PageList class contains lots of filterByStuff methods. I think the idea is you’d use one of them unless you have some very edge case kind of filtering in mind.

@mnakalay I’m all over those Page List Methods like a fly on a turd at the moment. Looking around, it appears we need to use the $list->getQueryObject() method for this now, as mentioned here: Searching and Sorting with the PageList object, under Advanced Techniques. Although I haven’t tested it yet, it appears to be the new goto! Other than that, there seems to be no other, yet obvious, way to do it…

I’m not sure you really need that. Those are all methods belonging to the class so if you have an instance of your PageList you should be able to do $pageList->filterBySmellOfTurd() and it should work without requesting the query object.

But that’s not tested either so you’ll still have to test it all.

@mnakalay Correct, and I understand how the shortened methods work. I’ve stuck to using the filterByAttribute() approach. In this case, trying to feed the filterBy methods ‘cvName’ is not working, as it’s a db field, rather than the attribute handle filterBy is looking for.

What I’m aiming to do is filter a list by the current page id/object to remove it, without the need to run another loop on the pages array after its created. So, in my use case:

$this->list->filter('cvID', Page::getCurrentPage()->getCollectionID(), '!=');

works perfectly, but is deprecated and not PRB acceptable, forcing me to loop the pages array again…

I am not at my desk at the moment, so cant provide details. There should be an equivalent method for implementing similar. Also, as the list is on a complex join of tables, you may need to specify the table as well as the column to filter on.

I’ve also checked \Concrete\Core\Search\ItemList\Database\ItemList, where it’s also marked as deprecated, to no avail. This isn’t make or break by any means. I was just hoping there was another obvious replacement way to do this!

@enlil PageList has a method filterByName() which filters by cvName. Can’t you use that since you wanted to filter by cvName?

If you still want to filter by page ID you can just create your own class that extend PageList and add your own method to it and use that instead of PageList

3 months later, I’ve just found the solution for this deprecation…

if ($this->excludeCurrentPage == 1) {
$ID = Page::getCurrentPage()->getCollectionID();
foreach ($this->list->getResults() as $p) {
if ($p->getCollectionID() == $ID) {

		$expr = $this->list->getQueryObject()->expr();
		$this->list->getQueryObject()->andWhere($expr->neq('p.cID', $p->getCollectionID()));