TransWikia.com

Custom module with config exposed in json api

Drupal Answers Asked by Daniel Harper on November 8, 2021

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);

    $this->config('mars_spot_collection.defaultcollections')
      ->set('default_collection_title', $form_state->getValue('default_collection_title'))
      ->set('default_collection_description', $form_state->getValue('default_collection_description'))
      ->save();
  }

How do I make this conig available in the JSONAPI?

Cheers

One Answer

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.

Answered by Shawn Conn on November 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP