If you have a translatable node with a paragraph, deleting one of the translations causes that content of node is deleted. For instance, create a paragraphed content type in any language, add Translation(s) to it into desired language. After deleting translation (with non-Original language), content is erased.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

michaellander created an issue. See original summary.

michaellander’s picture

The problem may be withinDrupal\paragraphs\Plugin\Field\FieldWidget::initIsTranslating(), when removing:

if ($this->isTranslating != NULL) {
    return;
 }

I was able to create separate translated nested paragraphs. However I'm not familiar enough with this piece to know what purpose that statement is serving.

miro_dietiker’s picture

This is indeed critical and needs a fix and extended test coverage.

Even if people don't know how to fix it, writing a test for it would be a great start.

ModernMantra’s picture

Discussed with @berdir, and seems that this bug report is related to Meta issue 'Support translatable paragraph entity reference revision field'. As @berdir suggests, this issue should go in slightly chnaged direction. Namely, we should fix the problem 'when translation is deleted, content is gone'. So will soon provide a test coverage for that.

ModernMantra’s picture

Status: Active » Needs review
FileSize
1.69 KB

Done testing in UI with @berdir, and paragraph is erased in node when changing translation, however tests show totally different. Strange...

Berdir’s picture

Status: Needs review » Needs work

I said deleting a translation, that's something very different than changing the language.

Also, the title and issue summary needs to be updated.

ModernMantra’s picture

Title: Nested paragraphs not working with Translations » Deleting Translation deletes content
Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.1 KB
2.03 KB

Here is new test only patch that makes deleting translation. Hope that steps in tests are good. Also changed summary and title.

Berdir’s picture

That looks better, should fail now.

The code that actually deletes is in \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::delete()

delete() is called per-translation. We should open a new issue in ERR that is related to this. We have existing API tests there in \Drupal\entity_reference_revisions\Tests\EntityReferenceRevisionsCompositeTest::testEntityReferenceRevisionsCompositeRelationship() where ew delete.

We need to extend that with API tests for this.

Note that to delete a translation, what you need to do on the API is call removeTranslation() and then save().

We should test those two things on the API level:

1. Create an entity like done there with a composite, add a translation. Delete the entity. This must delete the composite.
2. Create an entity like it does there with a composite, add a translation. Delete the translation. This must not delete. Then delete the entity, now we must delete the composite.

Thinking about it, this might even be a core issue, but we still need test coverage in ERR anyway, so start with that.

The core issue might be somewhere in \Drupal\Core\Entity\ContentEntityStorageBase::invokeFieldMethod(). We should not call a delete() on a non-translatable field at all there. If you can write a test, then I can look into this later today.

ModernMantra’s picture

So, created an issue in ERR, soon will be test there.

miro_dietiker’s picture

Status: Needs review » Needs work

Committed the related ERR issue.

Can someone please provide a summary of the current (remaining) status of this issue and how to move forward?

Berdir’s picture

Category: Bug report » Task
Priority: Critical » Normal

We could write paragraph specific test coverage to ensure it works here as expected as well but there is no bug anymore.

michaellander’s picture

This issue originally started because nested paragraphs were shared between translations instead of them being separate for each, has that issue been addressed?

If you have a translatable node with a paragraph containing an additional paragraph, the nested paragraph is shared by all hosts.

Node(en) -> Paragraph(en) -> *Paragraph(en)
Node(es) -> Paragraph(es) -> *Paragraph(en)
* Same paragraph entity

It turned into an issue about deleting one translation deletes both, but that was occurring because the translations weren't recursively applying to nested paragraph entities.

Berdir’s picture

Paragraphs does not support translated fields (yet). There's a separate issue to introduce that feature but for now, it doesn't work at all. And if you use that patch, then you need to report bugs there in that issue.

michaellander’s picture

Thanks @Berdir. I'll follow-up there.

johnchque’s picture

Issue tags: +Needs tests

Not urgent because it is fixed but tests are needed anyway.

supertony’s picture

@ yongt9412, in which version was this fixed? I'm using 8.x-1.1 and seeing a similar issue.

What's happening, for example, I have an English content and translated it into Chinese. I edit the English version, save the page and everything is deleted from the original node.