AnswerBun.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!

Related Questions

Node is not created, but nid is returned

2  Asked on December 26, 2021 by ziobudda

   

EntityDrupalWrapper->value() causes infinite recursion on user login?

1  Asked on December 24, 2021 by tigertrussell

   

Feed import breaks due to ajax error

1  Asked on December 24, 2021 by kenpeter

 

Multi site Image cache issue

0  Asked on December 24, 2021 by user99683

   

How to make relationships between users

1  Asked on December 22, 2021

   

Need CKEditor to encode special characters

1  Asked on December 22, 2021 by bemarlan

   

Checkboxes in a simple form are not displayed

1  Asked on December 22, 2021 by sebish

   

How to change scheduler date format in *_node_form

1  Asked on December 21, 2021 by oskar-calvo

   

hiding taxonomy terms on term page

1  Asked on December 21, 2021 by user3027413

   

TypeError on “drush config-export”

1  Asked on December 21, 2021

     

“Broken pipe” between Nginx and PHP-FPM

1  Asked on December 21, 2021 by stephen-winnall

 

Restrict delete operation on a node referenced by another node

2  Asked on December 19, 2021 by user48552

   

How to perform views date calculations using global math?

2  Asked on December 19, 2021 by tinohuda

   

Get menu link siblings

4  Asked on December 19, 2021 by erin-mclaughlin

 

Ask a Question

Get help from others!

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