georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
260 stars 352 forks source link

Filter news by categories with multiple select fields #2495

Open kanow opened 3 weeks ago

kanow commented 3 weeks ago

Bug Report

Current Behavior I'm adding a news plugin with no category restriction, to show all news from a sysfolder. In fluid template I built two select fields for categories. If I select only one category in the first select field, te result is empty. If I select categories in both of the select fields, then the result is not empty. It shows news data with selected categpories due to the category conjunction "and". The reason for that is an empty second category in demand object

categories => protected array(2 items)
         0 => '39' (2 chars)
         1 => '' (0 chars)

If I change categoryConjunction to "or" it works. But thats not what I want. I need categoryConjunction to "and" for the two categories to get the expected result.

Expected behavior/output Get the news with the selected category in the search result also if only one select field was used to select a category.

Environment

Possible Solution Use array_filter to remove empty values Add this line after line 205 in NewsController in the overwriteDemandObject method.

$propertyValue = is_array($propertyValue) ? array_filter($propertyValue) : $propertyValue;

Maybe array_filter is not the best solution, not sure.

georgringer commented 3 weeks ago

maybe use explode + GeneralUtility::intExplode(',', $array, true)