Problem/Motivation
When deleting a translation of an entity I encounter an error
InvalidArgumentException: The entity object refers to a removed translation (fr) and cannot be manipulated. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 576 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->get('title') (Line: 1311)
Drupal\Core\Entity\ContentEntityBase->getEntityKey('label') (Line: 1262)
Drupal\Core\Entity\ContentEntityBase->label() (Line: 116)
Drupal\Core\Entity\ContentEntityDeleteForm->logDeletionMessage() (Line: 76)
Drupal\Core\Entity\ContentEntityDeleteForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
This happens because in the logDeletionMessage() function we try to access the label of a deleted translation.
Steps to reproduce
Delete a translation for an entity (not the default translation).
Proposed resolution
We already have $message which is the value returned from getDeletionMessage(). We should just log this message, we already send it via the messenger service.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #3
quietone commentedI was recently testing another issue which included deleting a translation and did not encounter this error.
Is this reproducible on a fresh install?
Comment #4
vinmayiswamy commentedHi, I attempted to reproduce the issue described here but was unable to replicate the error.
Below are the steps I followed:
Setup:
* Installed Drupal 11.x on a fresh local environment.
* Enabled required modules: Content Translation, Language, and Locale.
Language Configuration:
* Added Telugu and French as new languages via Configuration > Regional and language > Languages.
Content Type Configuration:
* Enabled translation for the Article content type via Configuration > Regional and language > Content language and translation.
* Ensured fields like Title and Body are set to translatable.
Content Creation and Translation:
* Created an Article with a title and body in the default language (English).
* Added Telugu and French translations for the Article, providing translated titles and bodies.
Translation Deletion:
* Deleted the Telugu and French translations from the Article.
Observations:
* No
InvalidArgumentExceptionwas encountered.* Checked Reports > Recent log messages: No related errors found.
Additional Information:
* Cache was cleared during the process.
* Debug mode was enabled in
settings.php.* Verified on multiple content types and with different languages.
If there are any specific configurations or steps that might have been missed, please let me know. Based on my testing, the issue does not appear to be reproducible in the current setup.
Thanks!