#111273Allow combining multiple values in PersistedAliasMapper to allow slug-mapping arbitrary many filters
Description
Often you have a frontend plugin with some kind of filtering, like categories. However, most common extensions, like ext:news for example, only allow for mapping a single filter into a nice routing slug. In the end, this often comes from the fact that Extbase array arguments are used like tx_ext_plugin[filter][0]=1&tx_ext_plugin[filter][1]=2 and the routing can only map explicit parameters one-by-one.
However, when writing a plugin that puts mutliple filters into a single GET variable as a CSV list, like tx_ext_plugin[filter]=1,2 it is totally possible from the POV of the Routing API to map this into something nice-looking.
The core provides the PersistedAliasMapper, this can currently only handle a single value, however. I propose to extend it so that it can handle multiple values. I did this and it works flawlessly, I even just extended the core PersistedAliasMapper, like the following code shows. All it does is to explode() either the given GET param value or the given slug, run the original generate/resolve logic on each and re-@implode()@ it, nothing more, nothing less:
final class MultiPersistedAliasMapper extends PersistedAliasMapper
{
private const int MODE_GENERATE = 1;
private const int MODE_RESOLVE = 2;
public function generate(string $value): ?string
{
return $this->transformList($value, self::MODE_GENERATE);
}
public function resolve(string $value): ?string
{
return $this->transformList($value, self::MODE_RESOLVE);
}
private function transformList(string $commaSeparatedValues, int $mode): ?string
{
$multiValues = [];
foreach (\explode(',', $commaSeparatedValues) as $singleValue) {
if ($mode === self::MODE_GENERATE) {
$multiValues[] = parent::generate($singleValue);
} else {
$multiValues[] = parent::resolve($singleValue);
}
}
return \implode(',', $multiValues) ?: null;
}
}
It would be super nice if the core-provided PersistedAliasMapper could do this out of the box, by just adding a foreach into generate() and resolve(). The CSV-separator should be configurable in the YAML (multiAliasesSeparator or so), and maybe also have an explicit on/off-switch in the YAML (enableMultipleAliases: true) for existing edge-cases. But that’s basically it. I think this would be usefull for a lot of people.
This allows for having filter-enabled URLs like my.site/en/page/list/filter/nice-category,another-one,category-three/page-2, even works with pagination and everything.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[FEATURE] Allow combining multiple values in PersistedAliasMapper to allow slug-mapping arbitrary many filters Resolves: #111273 Releases: main