JsConfigureForm.php in JS Callback Handler 8.3
File
src/Form/JsConfigureForm.php
View source
<?php
namespace Drupal\js\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class JsConfigureForm extends ConfigFormBase {
public function getFormId() {
return 'js_configure_form';
}
public function getEditableConfigNames() {
return [
'js.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('js.settings');
$form['endpoint'] = [
'#type' => 'textfield',
'#title' => $this
->t('JS Callback Endpoint'),
'#description' => $this
->t('The endpoint used for all JS Callback requests.', [
'@endpoint' => $form_state
->getValue('endpoint', $this
->config('js.settings')
->get('endpoint')),
]),
'#default_value' => $form_state
->getValue('endpoint', $config
->get('endpoint')),
];
$form['silence_php_errors'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Silence PHP Errors'),
'#description' => $this
->t('Prevents custom JS Callback Handler PHP error and exception handlers from being invoked.'),
'#default_value' => $form_state
->getValue('silence_php_errors', $config
->get('silence_php_errors')),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('js.settings');
$config
->set('endpoint', $form_state
->getValue('endpoint') ?: '/js');
$config
->set('silence_php_errors', $form_state
->getValue('silence_php_errors') ?: FALSE);
$config
->save();
parent::submitForm($form, $form_state);
}
}