inspiredminds/contao-news-filter-event
最新稳定版本:1.2.0
Composer 安装命令:
composer require inspiredminds/contao-news-filter-event
包简介
Contao extension that provides an event to filter a news list.
README 文档
README
Contao News Filter Event
Contao provides a way to output custom news items in the news list module via the newsListFetchItems hook. However,
if two or more extensions want to filter the news items according to some parameters, only one can win. This Contao
extension instead provides a NewsFilterEvent where you can basically customize the parameters of the
NewsModel::findBy() call that will fetch the news items from the database. Multiple extensions can add their
conditions and thus the news list can be filtered down by multiple parameters provided by these different extensions.
For example, the following event listener would filter the news list via an author query parameter:
// src/EventListener/AuthorNewsFilterListener.php namespace App\EventListener; use InspiredMinds\ContaoNewsFilterEvent\Event\NewsFilterEvent; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\HttpFoundation\RequestStack; #[AsEventListener] class AuthorNewsFilterListener { public function __construct(private readonly RequestStack $requestStack) { } public function __invoke(NewsFilterEvent $event): void { $request = $this->requestStack->getCurrentRequest(); $authorId = max(0, (int) $request->query->get('author')); if (!$authorId) { return; } $event ->addColumn('tl_news.author = ?') ->addValue($authorId) ; } }
See here for further examples.
统计信息
- 总下载量: 3.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2023-03-27