It is possible to use a dynamic entity type for upcasting parameters in routes. Here is an example from the Comment module:
comment.reply:
path: '/comment/reply/{entity_type}/{entity}/{field_name}/{pid}'
defaults:
_controller: '\Drupal\comment\Controller\CommentController::getReplyForm'
_title: 'Add new comment'
pid: ~
requirements:
_custom_access: '\Drupal\comment\Controller\CommentController::replyFormAccess'
options:
parameters:
entity:
type: entity:{entity_type}
If a non-existing entity type is now used in a URL a PluginNotFoundException
is thrown, resulting in a 500 Internal Server Error. Here is an example when calling this route on the Comment module with the non-existing entity type "fnode" (eg /comment/reply/fnode/1/field_comments/1
):
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "fnode" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 125 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Solution: we should catch this exception and return a 404 Page Not Found instead.
Comments
Comment #2
pfrenssenComment #9
marioki CreditAttribution: marioki commentedI'm surprised that nobody else has this issue. I haven't found anything else about this online yet. Still an issue now.
Comment #11
mpp CreditAttribution: mpp as a volunteer and at AmeXio for District09 commentedIt looks like this issue has been resolved in 9.1.x, see https://github.com/Gizra/og/runs/2388562288.
Comment #12
mpp CreditAttribution: mpp as a volunteer and at AmeXio for District09 commentedI believe this has been solved in https://www.drupal.org/node/3193771.