Problem/Motivation

if ($field->getFieldDefinition()->getTargetEntityTypeId() == "paragraph") { compare to FieldConfigBase:;getTargetEntityTypeId: return $this->entity_type; meaning if you have an entity revisions reference field it will always get duplicated even if the target is not a paragraph.

The same method WSODs hard if the entity referenced doesn't exist.

Proposed resolution

Change to getSetting('target_type') and check whether the referenced entity exists.

Remaining tasks

Do it.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Charlie ChX Negyesi created an issue. See original summary.

ghost of drupal past’s picture

Status: Active » Needs review
StatusFileSize
new945 bytes

I also fixed a problem where duplicating a broken reference wsods.

ghost of drupal past’s picture

Title: createDuplicate is checking the wrong entity type » createDuplicate is checking the wrong entity type and WSODs on broken reference
Issue summary: View changes
ghost of drupal past’s picture

StatusFileSize
new1.33 KB

I believe this is much nicer. (It doesn't check for a revisions reference but IMO that's irrelevant.)

berdir’s picture

I'm not sure about that being better. The behaviour of paragraphs not being reusable is tied to ERR fields. We currently actually don't allow creating ER fields with paragraphs as target to avoid misconfiguration, but did in fact recently have a case for doing so. Not on a paragraph entity in that case, but still.

berdir’s picture

It also wouldn't be in sync with \Drupal\paragraphs\EventSubscriber\ReplicateFieldSubscriber anymore.

ghost of drupal past’s picture

StatusFileSize
new1.35 KB

Sure. I just liked the interface better, this class doesn't have an interface but if this is what's needed, I can. The reason I thought it's nicer not because of that detail but because it drops the definition and also there are no strings, and also no ->entity: retrieval is via referencedEntities() and setting happens via the ItemList::offsetSet => ItemList::set => EntityReferenceRevisionsItem::setValue call chain so no need for ->entity.

berdir’s picture

Status: Needs review » Needs work

It might look nicer, but currently the referencedEntities() implementation is pretty bad, it always calls loadRevision() and there's no static cache for that yet. So I'd prefer to work with $item->entity, sorry :)

Not sure about a test, we have \Drupal\paragraphs\Tests\Experimental\ParagraphsExperimentalDuplicateFeatureTest::testDuplicateButtonWithNesting(), we could add a second ERR field that points to nodes or so, add a paragraph with two references, delete one to test the extra if check and then load the node after duplicating to make sure that the reference points to the same ID?

ghost of drupal past’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB

> It might look nicer, but currently the referencedEntities() implementation is pretty bad, it always calls loadRevision() and there's no static cache for that yet

...

which is not only a performance issue but also leads to data loss if the subparagraph has changes. #3098924: referencedEntities() causes data loss

So yes $item->entity it is.

berdir’s picture

Status: Needs review » Fixed

Committed.

ghost of drupal past’s picture

StatusFileSize
new1.56 KB

We had a problem where blocks were duplicated like no tomorrow due to this bug. Tonight I cleaned it up. The script is worthy of posting here.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.