OpignoTincanApiSettingsForm.php in Opigno TinCan API 3.x
File
src/Form/OpignoTincanApiSettingsForm.php
View source
<?php
namespace Drupal\opigno_tincan_api\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class OpignoTincanApiSettingsForm extends FormBase {
public function getFormId() {
return 'opigno_tincan_api_settings_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['endpoint'] = [
'#type' => 'textfield',
'#title' => 'Endpoint',
'#default_value' => \Drupal::config('opigno_tincan_api.settings')
->get('opigno_tincan_api_endpoint'),
];
$form['username'] = [
'#type' => 'textfield',
'#title' => 'User',
'#default_value' => \Drupal::config('opigno_tincan_api.settings')
->get('opigno_tincan_api_username'),
];
$form['password'] = [
'#type' => 'textfield',
'#title' => 'Password',
'#default_value' => \Drupal::config('opigno_tincan_api.settings')
->get('opigno_tincan_api_password'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$messenger = \Drupal::messenger();
$config = \Drupal::configFactory()
->getEditable('opigno_tincan_api.settings');
$config
->set('opigno_tincan_api_endpoint', trim($form_state
->getValue('endpoint')));
$config
->set('opigno_tincan_api_username', trim($form_state
->getValue('username')));
$config
->set('opigno_tincan_api_password', trim($form_state
->getValue('password')));
$config
->save();
$messenger
->addMessage($this
->t('LRS settings saved successfully'));
}
}