diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 8facb6ebab1c50ad2673c51f4afc09cae8ea8ab7..a9afd3a4aa89c69fdc4eab2911bd13d3f039080a 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -82,7 +82,7 @@ class BackendController extends ActionController { // retrieve next site root id $siteRootId = Utility::getSiteRoot((int) GeneralUtility::_GP('id')); $categories = Utility::getCategoriesForSiteRoot($siteRootId); - $news = Utility::getAllNewsByCategories($categories); + $news = Utility::getAllNewsByCategories($categories, $filters); $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent()); $this->view->assign('pageUid', $pageUid); diff --git a/Classes/Service/Backend/Utility.php b/Classes/Service/Backend/Utility.php index 9514defca269f8d1584da635c35def7067f17503..a14fef70a1561f0260a2373381716b7c19be513c 100644 --- a/Classes/Service/Backend/Utility.php +++ b/Classes/Service/Backend/Utility.php @@ -131,18 +131,39 @@ class Utility { } /** + * Get all news for the given categories (all if filter is empty) + * * @param array $categories + * @param array $filters * @return array * @throws \InvalidArgumentException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ - public static function getAllNewsByCategories(array $categories = []) { + public static function getAllNewsByCategories(array $categories = [], array $filters = []) { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); /** @var NewsRepository $newsRepository */ $newsRepository = $objectManager->get(NewsRepository::class); + // filter by category if set + if (!empty($filters['filters']['categories'])) { + foreach ($categories as $key => $value) { + if (is_array($filters['filters']['categories'])) { + $unset = TRUE; + foreach($filters['filters']['categories'] as $category) { + if ($key == (int) $category) { + $unset = FALSE; + } + } + + if ($unset) { + unset($categories[$key]); + } + } + } + } + $categoryIds = []; - foreach($categories as $key => $value) { + foreach ($categories as $key => $value) { $categoryIds[] = $key; } diff --git a/Resources/Private/Partials/Backend/Filter.html b/Resources/Private/Partials/Backend/Filter.html index 5bae71aaa9d8bb7647c6f7e8b9843f8845df7ba2..53395972e523f116c4010e52f36bf54201c224cb 100644 --- a/Resources/Private/Partials/Backend/Filter.html +++ b/Resources/Private/Partials/Backend/Filter.html @@ -6,7 +6,7 @@ <f:translate key="backend.filters.category" /> <small><f:translate key="backend.filters.categories.description" /></small> </label> - <f:form.select class="form-control" multiple="1" size="4" property="categories" options="{categories}" id="filter-category" /> + <f:form.select class="form-control" multiple="1" size="4" property="filters.categories" options="{categories}" id="filter-category" /> </div> </div> <div class="col-xs-4">