In issue #3057545: ResourceTypeRepository wrongly assumes that all entity reference fields have the setting "target_type" there is a change coming that will probably affect this module. The summary as posted on the related issue:

Problem/Motivation

\Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition() directly reads the setting target_type from the field definition, however not all reference fields have this setting. A concrete example is the dynamic_entity_reference module, which allows for referencing multiple entity types and it lacks the setting target_type. See https://git.drupalcode.org/project/dynamic_entity_reference/blob/8.x-2.x...

Proposed resolution

Define a new interface, with a method named getReferenceableBundles(FieldDefinitionInterface $definition), which is then used to retrieve the entity types and bundles being referenced by that particular item class in a single API.

This is a pathway to effectively solving #3262385: Add an API for general entity reference field types by allowing code to introspect the field item class and determine if it implements this new interface.

CommentFileSizeAuthor
#4 3279702-4.patch13.81 KBjsacksick

Comments

bbrala created an issue. See original summary.

mglaman’s picture

I think the affected repository RenamableResourceTypeRepository can be removed, actually. This capability landed in Drupal core. In 9.3.x I believe. See #3105318: Add a public API for aliasing resource type names

bbrala’s picture

Yeah it did, if that is all it does you could use the core api ^^

jsacksick’s picture

Title: Overwritten method getRelatableResourceTypesFromFieldDefinition will change » Decorating the core ResourceTypeRepository is no longer necessary since 9.3
Status: Active » Needs review
StatusFileSize
new13.81 KB

Refactored the code to no longer decorate the resource type repository, let's see if the tests are still passing :).

jsacksick’s picture

Hah! What a shame, we can't actually get rid of this code for now, as we're pluralizing the resource path ("order" becomes "orders"). It seems we cannot support that with the wor that landed in core, correct?

jsacksick’s picture

Status: Needs review » Needs work

So yeah, maybe that was a poor change to make on our side, but it's too late now, we have a singular resource type name (e.g: order), and a plural resource name in the path (e.g: "orders").

Because of this, we probably have to stick with our overrides.

jsacksick’s picture

So while we probably still need to decorage the resource type repository, we could probably still do some refactoring, and stop overridding some parent methods.