WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Allow Custom Entities to Use EntityProvider #27859

Open spencerfinnell opened 3 years ago

spencerfinnell commented 3 years ago

Is your feature request related to a problem? Please describe.

core-data only creates context for default entities: https://github.com/WordPress/gutenberg/blob/master/packages/core-data/src/entity-provider.js#L20-L26

However, custom entities can be added with the addEntities action. These entities then not seen as valid by useEntityProp().

Describe the solution you'd like Instead of pulling from a static list of entities, all registered entities should be given context.

Describe alternatives you've considered Currently I have duplicated entity-provider.js and reference the local provider vs. Gutenberg's when using a custom entity.

yoscbd commented 2 years ago

you can find a solution here....

https://wordpress.stackexchange.com/questions/352500/get-post-from-custom-rest-endpoint-in-gutenberg

ndiego commented 1 year ago

The solution @yoscbd provided above does work, and I have implemented my own custom entities as well. Therefore, I am going to close this out.

spencerfinnell commented 1 year ago

Thank you for the link, however the solution linked does not address my original report (and I mention the ability to register entities with addEntities).

Yes, you can register custom entities for use by some hooks/functions, but not all.

My original issue is support for useEntityProp/EntityProvider which does not work with the technique provided above because entity context is only created for locally imported entities, not all registered entities: https://github.com/WordPress/gutenberg/blob/2e40379781f0a188d46afcf4afefd0c1aaad1c5f/packages/core-data/src/entity-provider.js#L28

spencerfinnell commented 1 year ago

@ndiego is it possible to reopen this so it remains visible? The original report is still a reproducible issue and blocker for things like https://github.com/WordPress/gutenberg/issues/43751#issuecomment-1233815717

ndiego commented 1 year ago

Yes, absolutely!