newsListCountItems
When you use custom news sorting or filtering using the newsListFetchItems
hook, you might also need to use the newsListCountItems hook, so that the pagination
works correctly. With this hook you return the number of news items, that would
be shown in the current request.
Parameters
array
$newsArchivesThe IDs of the news archives shown in this news list.
bool
$featuredOnlyWhether or not to show only featured news.
\Contao\Module
$moduleThe front end module instance executing this hook.
Return Values
Return false if this hook should not be considered. Return an integer otherwise. Return 0 if no news entries are found.
If the return value is anything other than false, no further hooks of type newsListCountItems will be executed!
Example
// src/EventListener/NewsListCountItemsListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Module;
#[AsHook('newsListCountItems')]
class NewsListCountItemsListener
{
public function __invoke(array $newsArchives, bool $featuredOnly, Module $module)
{
if (…) {
// Query the database and return the number of records
return $numberOfRecords;
}
return false;
}
}