Fatal error on translate tab

Created on 21 June 2021, about 3 years ago
Updated 21 December 2023, 6 months ago

Problem/Motivation

  • Translate tab is displayed for none translatable menu link content
  • When visiting the tab, user see fatal error
  • The module overrides any content translations access provided by core
  • The module is replacing all routs requirements set by core, which then overrides any other access checks from core, contrib and custom modules

See here the fatal error:

InvalidArgumentException: Field content_translation_source is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).{{Drupal\Core\Entity\ContentEntityBase->get('content_translation_source') (Line: 44) Drupal\content_translation\ContentTranslationMetadataWrapper->getSource() (Line: 142) Drupal\content_translation\Controller\ContentTranslationController->Drupal\content_translation\Controller

{​closure}​('en') array_filter(Array, Object) (Line: 144) Drupal\content_translation\Controller\ContentTranslationController->overview(Object, 'menu_link_content') call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber
{​closure}
​() (Line: 573) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber

{​closure}
​() (Line: 151) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)}}

Proposed resolution

  • Delegates the access for translating menu link content to core by applying some core's permissions ("Translate custom menu link" AND/OR "Create translations") AND "Manage translations for any entity that the user can edit". If you are using drupal 8, you need to apply the patch in this issue .
  • Remove the route alter for all entity.menu_link_content. Those alters are useless as the access is handled by menu_admin_per_menu_menu_link_content_access. However this hook won't be needed as well. see next 2 points.
  • Override the entity access handler for the menu_link_content. By doing this, we ensure that the access settings from core is still applied and this will respect any hook_entity_access check.
  • Remove menu_admin_per_menu_menu_link_content_access as we will handle the access for the menu_link_content by overriding the entity access handler class
  • Also the patch from this issue 🐛 The Translate tab is shown even though the logged-in user doesn't have the permission to translate content Needs work is needed to hide the translate tab.
🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇪Belgium msnassar

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.

  • 🇧🇪Belgium herved

    I attempted to rebase the MR but apparently I don't have the rights.
    Here's a patch against 8.x-1.x.

  • 🇧🇪Belgium herved

    And here is a patch against 8.x-1.5, if anyone else needs it.
    PS: our setup enforces static patches and MR diffs are not allowed (as they can change unexpectedly).

  • 🇬🇷Greece GiorgosK Chios, Greece 🇬🇷

    I had what it appeared as the problem described above and was able to resolve it without any patches

    it turned out that the menu item needed to be translatable

    /admin/config/regional/content-language > Custom menu link

  • 🇧🇪Belgium herved

    @GiorgosK Interesting, but what if we don't want to make custom menu links translatable?
    This PR goes beyond just fixing the PHP error AFAICS, but conceptually it seems to make more sense.
    I haven't really reviewed it, I only needed a reroll/static patch.
    Perhaps a maintainer could weight in?

Production build 0.69.0 2024