Needs work
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
6 Sep 2017 at 21:54 UTC
Updated:
7 Feb 2025 at 21:45 UTC
Jump to comment: Most recent, Most recent file
#2300677: JSON:API POST/PATCH support for fully validatable config entities intends to allow config entities to opt-in into typed data validation, something that only content entities were able to do until now.
Allow config entities to support typed data validation by implementing the new ValidatableInterface.
Review.
Nope.
Not really.
Nope.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2907163.patch | 2.53 KB | amateescu |
Comments
Comment #2
amateescu commentedThis should be enough I think.
Comment #3
dawehnerWhat I still don't understand, how can entities opt out of validation with this patch? How can rest module stop exposing content_moderation entities ... just this patch doesn't solve that bit :)
Comment #4
amateescu commented@dawehner, like I said in #2300677-190: JSON:API POST/PATCH support for fully validatable config entities and again in #194, I don't think we should introduce the ability for content entities to opt out of validation because it would be an API change. And even though the ContentModerationState entity type is internal, why wouldn't it support validation?
REST module should exclude that internal entity type in
\Drupal\rest\Plugin\Deriver\EntityDeriver::getDerivativeDefinitions().Comment #5
dawehnerWe had this discussion before in #2843753: Prevent ContentModerationState from being exposed by REST's EntityResource ... its a purely internal entity.
Fair, I guess content_moderation could exclude itself using some alter hook, if really needed.
One question about
\Drupal\Core\Entity\FieldableEntityInterface::isValidationRequired... why is this not used at all in Drupal core? Is it just me that this smells like another bug?Comment #6
amateescu commentedAnd purely internal entities should also be validatable before saving (potentially invalid) data to the storage, no?
That's because
\Drupal\Core\Entity\ContentEntityBase::preSave()decided to access thevalidationRequiredproperty directly and no other outside use came up so far.. I guess.Comment #7
dawehnerThank you @amateesc for the explanation this makes sense.
I'm calling out to @tim.plunkett whether he believes that adding these 3 methods to ConfigEntityInterface makes sense.
At least for me personally I like that config entities are free of typed data and everything typed data related is orthogonal.
Comment #8
amateescu commented@dawehner, who said anything about adding these 3 methods to
ConfigEntityInterface? This issue proposes to introduce an interface that *can* (not should, nor must) be implemented by a config entity type. For example:class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface, ValidatableInterfaceI really don't understand what's so confusing about this issue :)
Comment #9
tedbowI made a patch on #2300677-200: JSON:API POST/PATCH support for fully validatable config entities that takes this patch and applies it to that issue.
I like the way it simplifies that logic. I add the trait there to the
ConfigTestentity and made a trait for basic validation that implements the methods inValidatableInterfacethat was basically does what we were doing inConfigEntityResource. So basically if an ConfigEntity want the basic validation of typed data they can just implement the interface and use the trait.Also before this idea in #2300677: JSON:API POST/PATCH support for fully validatable config entities we were only validating in the REST resource so if so it would not be obvious for a developer how to validate a config entity if they were making one programmatically.
Comment #10
wim leersIt already does this:
content_moderation_rest_resource_alter().😱
@amateescu said in the other issue that we'd add this on a per-config entity type basis. In other words: to those config entity types that add support for validation. So for example
class NodeType extends ConfigEntityBundleBase implements NodeTypeInterfacewould change toclass NodeType extends ConfigEntityBundleBase implements NodeTypeInterface, ValidatableInterface(EDIT d'oh that's the example @amateescu gave in #8, sorry :PGreat point! This enhances the PHP DX.
Comment #11
wim leersComment #12
dawehnerWell I'm still not convinced of putting typed data level stuff on config entities, but it seems to be nobody gives a shit.
Comment #13
wim leersI didn't mean to bypass you, Daniel. I thought you had just misinterpreted. Probably means I'm missing something. Moving back to prior state.
Comment #14
wim leers#2300677: JSON:API POST/PATCH support for fully validatable config entities is major, this is a blocker, so bumping this to major too.
Comment #15
dawehnerI mostly try to keep things maintainable.
As of now config schema for example is not required for config entities to work, but rather are departed completely.
At least for me validation is just another level of config schema, also based upon typed data, but this time instead based upon constraints.
Don't get me wrong, there are advantages of putting stuff onto this interface as well.
Comment #16
tedbow@dawehner is you concern that with #2300677-184: JSON:API POST/PATCH support for fully validatable config entities #184 and before the typed data validation was something that happened on the Config REST resource level, i.e if you were using REST then typed data validation is not connected to Config entities....
But with this patch for any Config Entity that implements that new typed data validation will directly become part of the Entity itself?
Comment #17
dawehnerBut with this patch for any Config Entity that implements that new typed data validation will directly become part of the Entity itself?
Yeah basically. I think asking some of the configentity maintainers would be fair, given they can judge this better.
Maybe the answer will be: Its okay to add this one but limit to any further change.
One general question, is there a reason why we could not do this issue after the rest config issue? Could we introduce some other temporary way to flag config entites as validatable, but don't make this a public flag yet?
Comment #18
amateescu commentedHow is this patch putting any kind of typed data level stuff on config entities?
If we look at the documentation of these three methods, they have *nothing* to do with typed data.
Arguably, the only "problem" might be the return value documented by the
validate()method, which is an object that implementsEntityConstraintViolationListInterface, and that interface mentions "fields" in the signature of some of its methods, but those can simply be changed to mention "property" instead.So.. I really don't understand all the hate for this proposal.
Comment #19
amateescu commentedWe also need a small correction to
EntityConstraintViolationListInterfacebecause of the newValidatableInterfacethat we're adding here.Comment #20
tim.plunkettI read through #7, and didn't have to comment. But my question to Wim in slack was "why isn't config schema sufficient?"
Great to see @dawehner with similar thoughts.
Comment #21
amateescu commented@tim.plunkett, have you also read #8?
@dawehner in #7 was somehow under the impression that we're trying to add the validation methods to
ConfigEntityInterface, which is not the case.Comment #22
amateescu commentedAnd the new concern is that we're trying to shove typed data stuff into config entities, which is also not the case, as explained in #18 :)
Comment #23
tim.plunkettI misunderstood the scope of this issue. But mostly because I kept reading the last patch in #2300677: JSON:API POST/PATCH support for fully validatable config entities, which then starts applying it to config entities.
So, in a vacuum this patch is fine? But I'm very wary of the other issue.
Comment #24
amateescu commentedOk, then let's take it out of the vacuum and ask some real world questions.
The intention of #2300677: JSON:API POST/PATCH support for fully validatable config entities is pretty clear, it wants to extend rest.module's support for config entities, and in order to do that it needs config entities to be validatable.
Now, the real question is: how can we make config entities validatable with an API that is not REST-specific? I think the first step is what the current patch does.
What should be the next step? Implement one-off validation code for each config entity?
Comment #25
dawehnerThis is a weird question ... I hope we don't suggest people to validate on their own, instead of using our systems.
Let's just get this in, people seemed to not be convinced by my argument, cool.
Comment #26
xjm#25 isn't really convincing as an RTBC; please only RTBC things that you actually are signing off on as a peer reviewer. :)
So both @dawehner and @tim.plunkett have raised concerns about the longterm roadmap, that this might be used to add additional validation to config entity types other than their schemata. I understand that this is not being added to
ConfigEntityInterfaceor anything and not added to any config entity types yet, that it's only an option, etc. However, I think the concerns are legitimate.The concerns are:
I had all the same thoughts as I looked at this issue, and I'm not convinced by the arguments that they shouldn't be concerns. Like @tim.plunkett, I think this patch is fine as an improvement for the content entity API. Nice, even, as @tedbow says. So I think for all of us, the concerns are with #2300677: JSON:API POST/PATCH support for fully validatable config entities and not with this issue;. I'd like to see the relevant discussion of those concerns added to #2300677: JSON:API POST/PATCH support for fully validatable config entities before we proceed here. I'll also tag that issue for subsystem and framework manager review.
Also tagging this one for FM review since that's where we escalate when subsystem maintainers disagree, but let's please have an actual RTBC and attempt at consensus (or documenting the lack of consensus and counterpoints in the IS) before we do. :)
Comment #27
dawehnerIn case we decide to do this, we should file a follow up which does the following: It implements the validation inside a trait. This way we don't add the validation onto
ConfigEntityBase, given it would show the wrong signal.Comment #28
amateescu commented@dawehner, I think we can use #2912626: Configuration validation for that?
Comment #29
andypostIMO
ValidatableInterfaceis too broad better to prepend it kindaEntityFieldValidatationInterfaceComment #30
amateescu commented@andypost, the interface name is intended to be broad :) It also covers validation of entities as a whole (composite constraints), so it's not tied to fields.
Comment #31
dawehnerI really think #1818574: Support config entities in typed data EntityAdapter should be added before adding an interface and pretending to support customisability, where we actually don't support some.
Comment #32
wim leersOk, let's block this on #1818574: Support config entities in typed data EntityAdapter.
Comment #34
wim leersAs of #2300677-242: JSON:API POST/PATCH support for fully validatable config entities, this is no longer a blocker for that issue.
Comment #35
effulgentsia commentedRestoring what I think was an unintentional tag name change in #34.
Comment #46
tim.plunkettShould have been unpostponed 5 years ago, whoops
Comment #47
andypostComment #48
wim leersThis blocks #2300677: JSON:API POST/PATCH support for fully validatable config entities.
IMHO we should also do #2327883-108: Field [storage] config have incomplete settings until they are saved here, because without it, we won't be able to actually validate some config entities! 😱 (Which is the goal stated in the issue summary.)
Quoting #2327883-108:
@amateescu, do you have thoughts on how to do that? 🤓🙏
Comment #49
wim leersAlso, #3324150: Add validation constraints to config_entity.dependencies introduced
\Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::assertValidationErrors()which does:We
willmay need to update that for #48.Comment #50
wim leersDo we really still need this if #1818574: Support config entities in typed data EntityAdapter already made this possible? This code was committed to Drupal core in 2018:
Seems this is just a nice-to-have now?
Not to mention: not every config entity type will actually be validatable (we can guarantee this in core, not in contrib), so the existing
::isValidationRequired()is insufficient. We'd also need::isValidationSupported()or something like that?Demoting priority.
Comment #51
joachim commentedIt would still be really useful and a DX improvement if all entities, whether config or content, had the same API for validation.