Current Behavior
Using the \GeorgRinger\News\ViewHelpers\MultiCategoryLink\ArgumentsViewHelper will create duplicate cache entries for the same selection of categories, because the ViewHelper does keep track of the order in which categories are selected.
Select Category 5 $categoryList = '5'
Select Category 14 $categoryList = '5,14'
Deselect Category 5 $categoryList = '14'
Select Category 5 $categoryList = '14,5'
Deselect all $categoryList = ''
Select Category 5 $categoryList = ',5'
Expected behavior/output
Adding and removing a category must create uniform overwriteDemand.categories parameters, so the cache hash calculation returns the same hash for each unique selection.
Select Category 5 $categoryList = '5'
Select Category 14 $categoryList = '5,14'
Deselect Category 5 $categoryList = '14'
Select Category 5 $categoryList = '5,14' <-- Order the categories to prevent duplicate cache entry with different
Deselect all $categoryList = ''
Select Category 5 $categoryList = '5' <-- Without leading comma
Environment
TYPO3 version(s): 9LTS, 10LTS, 11LTS, 12LTS
news version: ^7.2, dev-main
Composer Mode: yes
OS: docker: php:7.2-fpm and up
Possible Solution
Use this code to add or remove categories from the list of categories and prevent leading commas.
// All IDs are numeric. Hence, split and type cast.
$categoryList = GeneralUtility::intExplode(',', $arguments['list'], true);
if ($arguments['mode'] === 'add') {
$categoryList[] = $categoryId;
} else {
// array_diff has the advantage, that it does not care how often the searched value occurs.
$categoryList = array_diff($categoryList, [$categoryId]);
}
// Ensure each ID to only occur once
$categoryList = array_unique($categoryList);
// Sort IDs, so lists are more uniform and less duplicate caches are generated
sort($categoryList);
$categoryList = implode(',', $categoryList);
Bug Report
Current Behavior Using the
\GeorgRinger\News\ViewHelpers\MultiCategoryLink\ArgumentsViewHelper
will create duplicate cache entries for the same selection of categories, because the ViewHelper does keep track of the order in which categories are selected.$categoryList = '5'
$categoryList = '5,14'
$categoryList = '14'
$categoryList = '14,5'
$categoryList = ''
$categoryList = ',5'
Expected behavior/output Adding and removing a category must create uniform
overwriteDemand.categories
parameters, so the cache hash calculation returns the same hash for each unique selection.$categoryList = '5'
$categoryList = '5,14'
$categoryList = '14'
$categoryList = '5,14'
<-- Order the categories to prevent duplicate cache entry with different$categoryList = ''
$categoryList = '5'
<-- Without leading commaEnvironment
Possible Solution Use this code to add or remove categories from the list of categories and prevent leading commas.