Bug #95072
closedCustom aspect leads to list view on hidden elements
0%
Description
I made a custom aspect for EXT:news for categories.
Everything works as expected but there is a problem with hidden elements or wrong links.
Instead of the error page with the http status 404 the site shows the list view or a server error(1/1) Symfony\Component\Routing\Exception\InvalidParameterException
Parameter "xxx" for route "tx_news_pi1_1" must match ".+" ("" given) to generate a corresponding URL.
I also made an mini extension to see if this is a EXT:news problem but the problem occurs there also.
I tried to separate list and show and tested 'limitToPages' with no luck.
The EXT is attached and this is my yaml config:
Test:
type: Extbase
extension: Test
plugin: Test
routes:
-
routePath: '/{title}'
_controller: 'Test::show'
_arguments:
title: test
-
routePath: /
_controller: 'Test::list'
-
routePath: '/{categoryName}'
_controller: 'Test::list'
_arguments:
categoryName: overwriteDemand/categories
defaultController: 'Test::list'
aspects:
title:
type: PersistedAliasMapper
tableName: tx_test_domain_model_test
routeFieldName: slug
categoryName:
type: CategoriesValueMapper
Files
Updated by Stephan Bauer about 3 years ago
- File clipboard-202109151627-kkb3v.png clipboard-202109151627-kkb3v.png added
- File clipboard-202109151627-zofzw.png clipboard-202109151627-zofzw.png added
On a test installation it shows the same problem a mentioned in #94585
Deaktivated Element:
Updated by Stephan Bauer about 3 years ago
- Related to Bug #94585: Siteconfig - 404 error not triggered if routeEnhancers is configured added
Updated by Oliver Hader about 2 years ago
- Assignee set to Oliver Hader
- Sprint Focus set to On Location Sprint
Updated by Oliver Hader about 2 years ago
I've just analyzed the provided CategoriesValuesMapper
and found the problem there. URL that cannot be resolved need to return null
, in that mapper example, the return value is always a string (which might be empty).
public function resolve(string $value): ?string { //DebuggerUtility::var_dump($value, 'resolve'); $categorieIDsArray = explode('_',$value); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category'); $categories = $queryBuilder->select('uid', 'slug') ->from('sys_category') ->where( $queryBuilder->expr()->in('slug', $queryBuilder->createNamedParameter($categorieIDsArray, Connection::PARAM_STR_ARRAY)), ) ->orderBy('parent') ->execute() ->fetchAll(); $routing = strval($categories[0]['uid']); ### -> ### ^^ that's the problem, `$routing` is always as string if($categories[1]) { $routing .= "," . strval($categories[1]['uid']); } if (isset($routing)) { return (string)$routing; } return null; }
Potential modification to return null
when having mismatches (and have 404 handling working):
public function resolve(string $value): ?string { //DebuggerUtility::var_dump($value, 'resolve'); $categorieIDsArray = explode('_',$value); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category'); $categories = $queryBuilder /* ... */ ->fetchAll(); // no category could be resolved, return `null`, triggers 404 handling if (!isset($categories[0]['uid'])) { return null; } $routing = $categories[0]['uid']; if (isset($categories[1]['uid])) { $routing .= "," . strval($categories[1]['uid']); } return $routing; }
Updated by Oliver Hader about 2 years ago
- Status changed from New to Closed
Adjusting the custom aspect mapper to return null
for mismatches resolved the problem. I'm closing this issue. Please feel free to reopen, in case you think that there's still something in the TYPO3 core that needs to be changed. Thx!