Problem/Motivation
This is a part of #2960253: [meta] Allow Paragraphs widget/field and similar use cases to to be considered translatable which is being split into 3 separate issues and converted to a meta issue.
* While we don't want the paragraph field values to be replaced, we basically need to be able to apply the same/similar logic to our referenced entities. So when a new "merge-revision" of the node is created, we want to do the same to the paragraphs, so that they too merge their translatable/untranslatable fields together. And later on when we have fancy conflict resolution that will replace this special case, we'll need to be able to apply that recursively as well.
Proposed resolution
Add hook_entity_revision_create() and hook_ENTITY_TYPE_revision_create()
Remaining tasks
User interface changes
None
API changes
Two new hooks, no changes.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | revision-create-hooks-2975754-2.patch | 10.69 KB | berdir |
Comments
Comment #2
berdirThese are the relevant parts from the other issue.
Comment #3
hchonovThe value of
$keep_untranslatable_fieldsmight change in the function body before the hooks are executed. We provide a documentation of the hook, which is explaining this, but this makes the whole pretty complex for developers. We could instead skip documenting that NULL should be assumed as TRUE and instead of calling the hooks with value of NULL we call them with value of TRUE if we've changed the value in the function body before calling the hooks. What do you think about this?Comment #4
berdirJust providing more context for now, we discussed that in the meta issue, see comments #20-22 or so over there.
Comment #5
hchonovWell then probably we have to pass both values to the hook - the original one and the newly computed one, which has been used by the method.
Comment #6
berdirThe idea was that if you want to, you can recalculate the value yourself which is I think pretty well documented on the hook documentation.
I expect that cases where you really need to care about it are fairly rare, for example in ERR with the nested composite entity use case, I'm just passing it along again to createRevision().
Comment #7
plach@hchonov:
Tentatively marking this RTBC, feel free to unmark if you still have concerns.
Comment #8
plachComment #9
berdirstill wrong :)
Comment #10
alexpottI think we need a change record to announce the new hooks.
Comment #11
plach@alexpott:
An all-encompassing CR for the parent meta issue is available at https://www.drupal.org/node/2975280, I guess we should publish it once the meta itself is fixed, right?
Comment #12
alexpott@plach thanks for adding this issue to the CR :) https://www.drupal.org/node/2975280/revisions/view/10983402/10990108
Comment #13
plachYep, that was missing :)
Comment #14
alexpottThis description doesn't explain the NULL state.
Is there anyway we can remove the NULL state and set it to either TRUE or FALSE according to the logic specified in this comment?
Comment #15
berdir> Defaults to TRUE if the provided entity is the default translation and untranslatable fields should only affect the default translation, FALSE otherwise.
This is the part that tries to explains the NULL state. it is an implicit TRUE or FALSE depending on those two conditions. See discussion here and in the meta issue, the idea is that it is relatively easy to figure this out if it's null and if you really need it, but it also seemed important to us to be able to be able to know if it was set explicitly or not.
The need to use it is likely relatively rare (e.g. the ERR patch that uses this just passes it along to the nested createRevision() call and while passing NULL does make it a bit more complicated to use, it allows for all possible scenarios.
Comment #16
webchickIt sounds like this is a blocker for contrib, so adding that tag.
Comment #19
gábor hojtsyI created https://www.drupal.org/node/2985957 as a change record with a copy of the part of https://www.drupal.org/node/2975280 that is relevant for this issue. Ideally all issues would be committed and that big CR published, but if there is no CR for this and the rest cannot make it, then we are not allowed to commit this one either. So let's make that possible at least :) We make this CR a redirect later or replace its body with a link to the bigger CR once it becomes obsolete.
Also giving all the credits possible here. Also carried over credits from #2960253: [meta] Allow Paragraphs widget/field and similar use cases to to be considered translatable.
Comment #22
gábor hojtsyThanks for the explanation @berdir, makes sense to me.
Committed 1e8a4de and pushed to 8.7.x and merged to 8.6.x. Thanks!
Comment #23
plach@Gábor Hojtsy:
Thanks for committing this, a separate CR makes sense for now, I just wanted to point out that the only other core ticket mentioned in the parent CR is #2826021: FieldItemList::equals is sufficient from the storage perspective but not for code checking for changes, which has stalled but seemed very close at a certain point, so we might still be able to fix core parts before alpha.
Comment #25
matsbla commentedTo me it seems like this hook is not always fired when creating new revisions, I made a new issue about it here #3031405: New hook_entity_revision_create() is not always fiered when new revisions are created