Scenario
1. Have a route with an entity_revision parameter.
Example:
node.revision_edit:
path: '/node/{node}/revisions/{node_revision}/edit'
defaults:
_entity_form: node.edit
_title: 'Edit revision'
requirements:
access: 'update'
options:
_node_operation_route: TRUE
parameters:
node:
type: entity:node
node_revision:
type: entity_revision:node
2. Access the route with an entity revision ID that doesn't actually exist. Example: /node/1/revisions/-9999/edit
Expected result: 404 page not found
Actual result:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Entity\EntityRepository::getTranslationFromContext() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php on line 61 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 82 of core/lib/Drupal/Core/Entity/EntityRepository.php).
Solution
Have EntityRevisionParamConverter do the proper checking before calling the getTranslationFromContext method.
Comments
Comment #2
stefan.butura commentedComment #3
stefan.butura commentedComment #4
hchonovNice find.
In this case it is sufficient to just check if $entity evaluates to TRUE -
$entity ? $this->entityRepository->getTranslationFromContext($entity) : NULL;Now we only need a test for it :)
Comment #12
mohit_aghera commentedI came across this issue during bugsmash triage.
This has already been fixed in latest Drupal 11.x by issue #2808163: Support dynamic entity types in the EntityRevisionParamConverter
Latest changes in 11.x looks good. https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...