Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi All,
Small question here,
I'm toying around with the JSON API and all works amazingly well.
Huge thanks for all effort into this amazing project.
1 question:
If I have an entity that contains a list text field (eg: field_status) with values
* Active
* Inactive
and I wanted to render a select list on my frontend when displaying that entity.
Is there a way that I can both retrieve the current value as well as all possible values?
So I can properly populate my select list.
Many thanks
Comments
Comment #2
Wim LeersGlad to hear it's working "amazingly well" for you :) Thanks for letting us know!
It totally makes sense that you want to retrieve the list of possible/allowed/valid values for a "list" field. We've got a long-existing feature request for this: #2822768: [PP-1] Add information about the schema in the json:api resource. In #2822768-11: [PP-1] Add information about the schema in the json:api resource I linked to the issue in the JSON:API spec where this is being discussed too. The key reason this is not yet supported is that the JSON:API spec does include such schema information.
*Maybe* this is supported by https://www.drupal.org/project/openapi, but I honestly don't know off the top of my head.
Without installing additional modules, you have two clear choices:
Field(Storage)Config
config entity, which you can read via JSON:API. This is similar to what https://github.com/jsdrupal/drupal-admin-ui does. And actually, perhaps you can just build on top of that project and/or reuse key parts of it? :)P.S.: please update to the 2.x branch of JSON:API as soon as you can, especially when this is a new project. The 1.x branch is minimally maintained, the 2.x branch is actively being developed and will go into Drupal core.
Comment #3
Wim LeersHaven't heard back in nearly 3 weeks, so I'm going to assume this helped :)