Needs work
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2016 at 16:05 UTC
Updated:
17 Jun 2022 at 06:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
amateescu commentedSomething like this.
Comment #3
amateescu commentedComment #4
wim leersLooking great!
This message must list the field name. Otherwise it'll be infuriatingly confusing.
c/p remnant
s/pre-existing/updating/
Comment #6
wim leersThe fails in the moderation test coverage here were fixed by #2824912: The moderation_state field incorrectly reports being read-only, I suspect.
Comment #7
amateescu commentedYup, but in general we shouldn't add this validation to computed fields, so here's a general fix for it.
Thanks for the review, fixed all those points.
I would surely hope we aren't able to change the value of read-only fields in the UI, so yes, this shouldn't introduce any change in the UI.
Comment #8
wim leersWe shouldn't? Shouldn't we disallow sending values for computed fields? Aren't all computed fields read-only by definition too? I guess that for something like the "path" field, a default value can be computed, but it's still modifiable — is that why not all computed fields are read-only too?
Besides that last question needing a solid answer, and probably needing documentation in the constraint's code, this looks ready to me. Although I think that this does need sign-off from somebody with deep Entity system knowledge: I don't think I can RTBC this.
Comment #10
amateescu commentedI don't think we should, maybe we just want to compute the value somewhere else and set it? :) Or.. what do you mean by "sending"?
Let me introduce you to #2392845: Add a trait to standardize handling of computed item lists :D
Here's the fix for the last test fail, we just need to update the test expectation since we're receiving an additional validation error now.
Comment #11
wim leersOh dear lord.
Oh, this makes sense!
If I read the comment, then I expect only the second condition to be applied. Because that first condition is also there, this needs a clarifying comment. If we should link to https://www.drupal.org/node/2392845 to improve this in the future, then that's fine.
Comment #12
wim leersNW just for that comment. Other than that, this looks ready IMO.
Comment #13
amateescu commentedBerdir points out that this would be quite a performance regression.
Comment #14
mglamanI asked @amateescu about berdir's concerns.
The constraint loads the unchanged entity and compares if the value changed.
In my opinion, the constraint would always throw a violation if
!$entity->isNew(). The value should not be considered valid if you're providing the value after the entity is created. Read-only values, as I have come to take them, are things you set when creating the entity.For instance: bundles are read-only.
In Drupal Commerce a payment method's payment gateway reference is read-only. A payment transaction can reference a payment method and its payment gateway. These are read-only. Each of these fields is populated when the entity is created and does not change.
Comment #15
mglamanRolling an updated patch.
Comment #16
mglamanHere is a reroll of #10. It takes into consideration #11 and doesn't check computed fields, as those wouldn't be receiving a value to be validated.
The constraint validator now merely checks if the entity is not new.
Comment #17
mglaman🤦♂️ I canceled the build.
I was thinking too simplistically and this causes any later save to mark those fields as invalid.
This would be somewhat easier if we could access the $values property on fieldable entities.
Comment #23
darvanenCould this be tackled with $entity->original or by loading the entity from storage to compare to?