69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Drupal\etherpad_api\Form;
|
|
|
|
use Drupal\Core\Form\ConfigFormBase;
|
|
use Drupal\Core\Form\FormStateInterface;
|
|
|
|
/**
|
|
* Configure Etherpad API settings for this site.
|
|
*/
|
|
class SettingsForm extends ConfigFormBase {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getFormId() {
|
|
return 'etherpad_api_settings';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getEditableConfigNames() {
|
|
return ['etherpad_api.settings'];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
|
$form['url'] = [
|
|
'#type' => 'textfield',
|
|
'#title' => $this->t('Etherpad API URL'),
|
|
'#default_value' => $this->config('etherpad_api.settings')->get('url'),
|
|
];
|
|
$form['key'] = [
|
|
'#type' => 'textfield',
|
|
'#title' => $this->t('Etherpad API key (found in instance root folder)'),
|
|
'#default_value' => $this->config('etherpad_api.settings')->get('key'),
|
|
];
|
|
return parent::buildForm($form, $form_state);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function validateForm(array &$form, FormStateInterface $form_state) {
|
|
if (!$form_state->getValue('url')) {
|
|
$form_state->setErrorByName('url', $this->t('The value is required.'));
|
|
}
|
|
if (!$form_state->getValue('key')) {
|
|
$form_state->setErrorByName('key', $this->t('The value is required.'));
|
|
}
|
|
parent::validateForm($form, $form_state);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
|
$this->config('etherpad_api.settings')
|
|
->set('url', $form_state->getValue('url'))
|
|
->set('key', $form_state->getValue('key'))
|
|
->save();
|
|
parent::submitForm($form, $form_state);
|
|
}
|
|
|
|
}
|