class JsonApiSettingsForm
Same name and namespace in other branches
- 10 core/modules/jsonapi/src/Form/JsonApiSettingsForm.php \Drupal\jsonapi\Form\JsonApiSettingsForm
- 11.x core/modules/jsonapi/src/Form/JsonApiSettingsForm.php \Drupal\jsonapi\Form\JsonApiSettingsForm
- 8.9.x core/modules/jsonapi/src/Form/JsonApiSettingsForm.php \Drupal\jsonapi\Form\JsonApiSettingsForm
Configure JSON:API settings for this site.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses \Drupal\Core\Form\ConfigFormBaseTrait extends \Drupal\Core\Form\FormBase
- class \Drupal\jsonapi\Form\JsonApiSettingsForm extends \Drupal\Core\Form\ConfigFormBase
- class \Drupal\Core\Form\ConfigFormBase uses \Drupal\Core\Form\ConfigFormBaseTrait extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of JsonApiSettingsForm
1 string reference to 'JsonApiSettingsForm'
- jsonapi.routing.yml in core/
modules/ jsonapi/ jsonapi.routing.yml - core/modules/jsonapi/jsonapi.routing.yml
File
-
core/
modules/ jsonapi/ src/ Form/ JsonApiSettingsForm.php, line 13
Namespace
Drupal\jsonapi\FormView source
class JsonApiSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'jsonapi_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'jsonapi.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$jsonapi_config = $this->config('jsonapi.settings');
$form['read_only'] = [
'#type' => 'radios',
'#title' => $this->t('Allowed operations'),
'#options' => [
'r' => $this->t('Accept only JSON:API read operations.'),
'rw' => $this->t('Accept all JSON:API create, read, update, and delete operations.'),
],
'#default_value' => $jsonapi_config->get('read_only') === TRUE ? 'r' : 'rw',
'#description' => $this->t('Warning: Only enable all operations if the site requires it. <a href=":docs">Learn more about securing your site with JSON:API.</a>', [
':docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/security-considerations',
]),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('jsonapi.settings')
->set('read_only', $form_state->getValue('read_only') === 'r')
->save();
parent::submitForm($form, $form_state);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.