Original paragraph not available in host entity hook_insert/hook_update

Created on 15 November 2018, about 6 years ago
Updated 26 May 2019, over 5 years ago

Problem/Motivation

* Have a (non-revisionable, e.g. user) entity and a field_paragraph
* Solve a problem where you need to act depending on the paragraph change (so need the original paragraph) *and* the host entity ID.

Expected:
* In hook_user_insert, developer can access $user->original->field_paragraph *or* $user->field_paragraph->original to get the original paragraph

Experienced:
* Nope

Note that acting in hook_paragraph_insert is not a workaround as $user->id() is not determined here.
OTOH, in hook_user_insert, the paragraph is already saved and $paragraph->original had been deleted by EntityStorageBase::doPostSave.

I worked around this by some userland caching of the original paragraph, but this is plain insane and a real kitten massacre.

Proposed resolution

I see 2 viable approaches:
a) Enrich $entity->original:
* 1) In presave, when $entity->original is set, care that all entityreference fields get a clone of its referenced entity.

b) Make $paragraph->original endure:
* 1) (By deferring the unset()) Somehow prevent or undo deleting $paragraph->original after paragraph save. Then delete it after last host entity is saved.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Hi @geek-merlin, did you manage to proceed with anything on this?

    I also need to log the changes in a Nested paragraph field but as you I can't see any original values in any hook:presave.

Production build 0.71.5 2024