I have a module with two pieces of config set using an admin form and Drupal the drupal config service.

Like this

   * {@inheritdoc}
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);

      ->set('default_collection_title', $form_state->getValue('default_collection_title'))
      ->set('default_collection_description', $form_state->getValue('default_collection_description'))

How do I make this conig available in the JSONAPI?



You can't do it. Not with the core JSON:API module. Out of the box, the resources JSON:API exposes are all the entity definitions from EntityTypeManager which includes content & config entities (defined by extending ConfigEntityBase).

However, arbitrarily set config values will not be exposed. JSON:API also doesn't support custom resources, as JSON:API docs state:

The JSON:API module provides no PHP API to modify its behavior. It is designed to have zero configuration.

• Adding new resources/resource types is unsupported: all entities/entity types are exposed automatically. If you want to expose more data via the JSON:API module, the data must be defined as entity. See the "Resources" section.

The JSON:API Resources project attempts to fill this in if you want to design your own endpoint with custom responses.

  • Thanks for the answer, I was curious why image styles were available in the json API and looked at the source code. It seems they're entity types that extend ConfigEntityBase so I think the answer needs adjusting as config entities are available in the json API. In my question I wasn't using config entities but the config factory which I don't think uses entites. – Daniel Harper Jul 21 '20 at 13:29
  • Updated. I remember mentioning that in the first draft but I think it got lost as I wanted to mention you can't control JSON:API to dump arbitrary data. Feel free to edit if you see something else missing. – Shawn Conn Jul 21 '20 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.