target instanceof ModelCriteria) { // process count $countQuery = clone $event->target; $countQuery ->limit(0) ->offset(0) ; if ($event->options[PaginatorInterface::DISTINCT]) { $countQuery->distinct(); } $event->count = (int) $countQuery->count(); // process items $result = null; if ($event->count) { $resultQuery = clone $event->target; if ($event->options[PaginatorInterface::DISTINCT]) { $resultQuery->distinct(); } $resultQuery ->offset($event->getOffset()) ->limit($event->getLimit()) ; $result = $resultQuery->find(); } else { $result = []; // count is 0 } $event->items = $result; $event->stopPropagation(); } } public static function getSubscribedEvents(): array { return [ 'knp_pager.items' => ['items', 0], ]; } }