CourseEnrollmentSettingsForm.php in Course 3.x
File
src/Form/CourseEnrollmentSettingsForm.php
View source
<?php
namespace Drupal\course\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\course\Entity\CourseEnrollmentType;
class CourseEnrollmentSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'course_enrollment_settings_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('course.settings.enrollment');
$types = CourseEnrollmentType::loadMultiple();
$options = array_column($types, 'label', 'id');
$form['default_enrollment_type'] = [
'#title' => t('Default course enrollment type'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $config
->get('default_enrollment_type'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('course.settings.enrollment')
->setData($form_state
->cleanValues()
->getValues())
->save();
parent::submitForm($form, $form_state);
}
protected function getEditableConfigNames() : array {
return [
'course.settings.enrollment',
];
}
}