codefog/contao-news_categories

Improve the newsListFetchItems Hook

Closed this issue · 3 comments

If the Contao Tags Bundle is used in parallel with this bundle, its newsListFetchItems hook no longer works.
This is because you always return a collection, even if no category filter is active.
Quick Fix:
Codefog\NewsCategoriesBundle\EventListener\NewsListener

public function onNewsListFetchItems(array $archives, $featured, $limit, $offset, ModuleNewsList $module)
{

    if (null === ($criteria = $this->getCriteria($archives, $featured, $module))) {
        return null;
    }

    $currentParam = $this->newsCategoriesManager->getParameterName();

    if (empty(Input::get($currentParam))) {
        return false;
    }
    ...

There can always only be one newsListFetchItems hook that actually filters the news.

An alternative solution is to use inspiredminds/contao-news-filter-event. There exists a bridge for the codefog/contao-news_categories extension: inspiredminds/contao-categories-news-filter.

In order for this to work with the numero2/contao-tags extension you would either need to build your own bridge, or the numero2/contao-tags extension needs to switch from using the newsListFetchItems hook to the NewsFilterEvent.

Just to be sure, I don't want to filter by categories and tags at the same time, but either or.
The numero2/contao-tags extension would make that possible ;)
But thanks for pointing out the codefog/contao-news_categories extension!

I agree though that NewsListener::onNewsListFetchItems should return false if category filtering is not enabled at all for the respective news list module.