User without translation permission get error messages on forms unrelated to translation.

Created on 15 June 2025, 20 days ago

Problem/Motivation

Users without auto translation permission get error messages on forms unrelated to translation.
If a user or anonymous user opens a form which is not related to translation and does not have permission to use auto translate, an error message is displayed. This happens on every form that triggers hook_form_node_form_alter.

The reason seems to be in auto_translation.module in the auto_translation_form_node_form_alter() hook. The only condition there to call the translation is that the form_id does not end with '_edit_form'. The translation checks the user rights and creates the error message.

For example, if the form is created like this:
$form = Drupal::service('entity.form_builder')->getForm($entity, 'default');
this will generate a form_id like node_my_entity_form which triggers the hook.

Steps to reproduce

This can be reproduced by opening a form as any user without auto translate permission, who has permission to edit any node where the form_id does not end with '_edit_form'.

Proposed resolution

I made a patch which checks if

  • the user has the permission 'auto translation translate content' and
  • the bundle of the form is an enabled content type

If one of those conditions is not met, translation will not be called.

What is not clear to me is the intention to use
if(!str_ends_with($form_id, '_edit_form')) {
in the hook.

I wonder if this might lead to problems if a user with the appropriate permission wants to translate certain entities. In the hook_form_media_alter the code checks if the form_id ends with '_add_form' rather than checking that the form_id does not end with '_edit_form'.

Would you care to discuss the reasoning behind this?

🐛 Bug report
Status

Active

Version

1.4

Component

Code

Created by

🇩🇪Germany Martin Mayer Germany and Philippines

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024