Content Translation Delete Access check invalid argument error

Created on 3 April 2018, over 6 years ago
Updated 21 September 2024, 27 days ago

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();
  }
🐛 Bug report
Status

Closed: works as designed

Version

11.0 🔥

Component
Content translation 

Last updated about 19 hours ago

No maintainer
Created by

🇬🇧United Kingdom benjas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands Lendude Amsterdam

    This feel like a specific issue to your setup, I would have expected more mentions of this if it was a more common problem.

    If this is something generic we will need some steps to reproduce on a clean Drupal install. If anybody could provide those that would be nice, or if you found a solution that would be great too

    Thanks!

  • Issue was unassigned.
  • Status changed to Closed: works as designed 27 days ago
  • 🇳🇿New Zealand quietone

    Since we need more information to move forward with this issue and it has not been supplied in over a year I am closing this issue.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

    Thanks

Production build 0.71.5 2024