Fatal error when using "Duplicate" action from a non-default-language UI on a translatable bundle
THE ERROR `Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\EntityBase->toUrl() (line 177 of core/lib/Drupal/Core/Entity/EntityBase.php).` HOW TO REPRODUCE 1. in a fresh Drupal cms, enable core’s 4 Multilingual modules (config_translation, content_translation, locale, language) 2. add a second language ( e.g. fr ) 3. enable content translation on ‘Utility page’ 4. create a new Utility page **Test** node and add a translation (e.g. node id 2) 5. visit e.g. /fr/node/2, click the **Duplicate** local task… 6. observe EntityMalformedException: _The "node" entity cannot have a URI as it does not have an ID._ WHERE THIS OCCURS (?) In ContentTranslationHandler:370 ``` // Replace the delete button with the delete translation one. if (!$new_translation) { $weight = 100; foreach (['delete', 'submit'] as $key) { if (isset($form['actions'][$key]['weight'])) { $weight = $form['actions'][$key]['weight']; break; } } … ``` DIAGNOSIS (?) Why isNewTranslation() doesn’t catch this: TRANSLATION_CREATED status is set only by ContentTranslationHandler::prepareTranslation() on the dedicated translation-add route. An entity produced by createDuplicate() carries TRANSLATION_EXISTING status on every translation (because clone $this deep-copies the $translations array), so isNewTranslation() returns FALSE on the active langcode even though the entity has never been saved. POTENTIAL FIX (?) `if (!$new_translation && !$entity->isNew()) {…}` This appears to fix the issue in my project, but did not try in Drupal CMS.
issue