Problem/Motivation
Upgraded to Drupal 8.5.x and after clearing the cache was presented with this error when visiting homepage and other node pages as authenticated or anonymous users:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\content_translation\Access\ContentTranslationDeleteAccess::checkAccess() must implement interface Drupal\Core\Entity\ContentEntityInterface, string given, called in /var/www/html/web/core/modules/content_translation/src/Access/ContentTranslationDeleteAccess.php on line 69 in Drupal\content_translation\Access\ContentTranslationDeleteAccess->checkAccess() (line 81 of core/modules/content_translation/src/Access/ContentTranslationDeleteAccess.php).
Further investigation I discovered the "getParameter()" in this function was returning just the node ID, not the loaded entity for the route "entity.node.delete_form":
public function access(RouteMatchInterface $route_match, AccountInterface $account) {
$requirement = $route_match->getRouteObject()->getRequirement('_access_content_translation_delete');
$entity_type_id = current(explode('.', $requirement));
$entity = $route_match->getParameter($entity_type_id);
return $this->checkAccess($entity);
}
Proposed resolution
I don't understand why the getParameter function from RouteMatchInterface is doing this but a simple work around could be to refactor the access function to check for a valid entity and pass back neutral if not. Note: according to this issue
https://www.drupal.org/node/2945956 →
further work TBC for revisions translation delete in Drupal 8.6.x. However not sure if problem is related to this previous fix -
https://www.drupal.org/node/2945956 →
.
This is what I would propose to fix:
public function access(RouteMatchInterface $route_match, AccountInterface $account) {
$requirement = $route_match->getRouteObject()->getRequirement('_access_content_translation_delete');
$entity_type_id = current(explode('.', $requirement));
$entity = $route_match->getParameter($entity_type_id);
if ($entity instanceof ContentEntityInterface) {
return $this->checkAccess($entity);
}
// No opinion.
return AccessResult::neutral();
}