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.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

bradjones1 created an issue. See original summary.

bbrala’s picture

Interesting, 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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

+1 for this.

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.

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.

bradjones1’s picture

IMHO anybody implementing these hooks should know what they're doing.

Yes.

wim leers’s picture

@bradjones1 If you can get a merge request + change record for this going, I promise I'll review 🤓

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.