steps to reproduce
0. Enable content moderation and enable editorial workflow for all content types.
1. Enabled translation.
2. Add a language in addition to default language.
3. create a node in default language
4. Add a translation in another language
5. Clone the translation created in step 4.
6. Attempt to delete the translation created in Step 5.

expected result: Translation is deleted:

Actual result: Error is thrown:

The specified translation (de) cannot be removed. in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save()</em> (line <em class="placeholder">829</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php</em>).

This is happening because when cloning a translation, a content moderation state is created for it. And the content moderation state entity is marked as the default language even though we are cloning a translation. See screen shot of db entries. Then when one tries to delete the translation, it triggers content_moderation delete hooks, which tries to delete the associated moderation state. Content moderation calls:
removeTranslation method in ContentEntityBase.php:

public function removeTranslation($langcode) {
    if (isset($this->translations[$langcode]) && $langcode != LanguageInterface::LANGCODE_DEFAULT && $langcode != $this->defaultLangcode) {
.....
.....
 else {
      throw new \InvalidArgumentException("The specified translation ($langcode) cannot be removed.");
    } 

The condition fails and we end up with the exception.

Suggested approach

Maybe entity clone should just check if the cloned entity is a translation and always clone the source (default translation).

CommentFileSizeAuthor
#3 Screen Shot 2018-07-10 at 11.48.56 AM.png112.92 KBawm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

awm created an issue. See original summary.

awm’s picture

Issue summary: View changes
awm’s picture

Issue summary: View changes
FileSize
112.92 KB
awm’s picture

this was actually caused by a patch #19 at https://www.drupal.org/project/drupal/issues/2901459.

awm’s picture

Status: Active » Closed (works as designed)