Problem/Motivation
Like other adjustments that are currently possible using ResourceTypeBuildEvent, I have a use case for having an entity type (one not backed by SQL storage) which is usable in json:api responses, but does not have automatic route generation or self URLs created.
The specific use case is using json:api as a gateway in front of the Instagram Basic Display API. This mostly works out of the box, but for a few things like the UUID not really being a UUID.
The rub comes when I want to be able to use jsonapi_resources as a de-facto replacement for the entityQuery-based controllers provided by json:api out of the box. I also need the entity type definition included in an openapi spec. I can't disable the resource type entirely, since that defeats the purpose of exposing it.
json:api's definition of mutable is "not a config entity" and locatable means "doesn't directly use null storage."
These determinations are made in static methods on the resource type repository and, like much of the json:api PHP API, is not easily overridden. I had to resort to some creative decoration pattern, especially since I'm also using both jsonapi_extras and jsonapi_cross_bundles.
The default rules for determining mutability and locatablility are correct in 99% of use cases. BUT, this is an area where it's extremely difficult to affect the resource type info. There is an event for making similar low-level rules (like disabling) and I think these two fields are candidates for similar treatment.
Comments
Comment #2
bbralaInteresting, makes sense to add at some point. Perhaps we do need to be carefull though that you don't break the API. Not sure if some sanity checks would make sense that core entities might not be overwriteable? I'm a bit scared this might lead to future bug reports.
Comment #6
wim leers+1 for this.
I'm definitely in favor of sanity checks. But what if a contrib module extends a core-provided entity type's capabilities, such as https://www.drupal.org/project/contact_storage?
IMHO anybody implementing these hooks should know what they're doing.
Comment #7
bradjones1Yes.
Comment #8
wim leers@bradjones1 If you can get a merge request + change record for this going, I promise I'll review 🤓