news icon indicating copy to clipboard operation
news copied to clipboard

Filter news by categories with multiple select fields

Open kanow opened this issue 1 year ago • 1 comments

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

  • TYPO3 version(s): 12.4.14
  • news version: 11.4.2
  • Is your TYPO3 installation set up with Composer (Composer Mode): yes
  • OS: Local docker environment with PHP 8.2

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.

kanow avatar Jun 18 '24 08:06 kanow

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

georgringer avatar Jun 18 '24 08:06 georgringer