CourseCommerceSettingsForm.php in Course 3.x
File
modules/course_commerce/src/Form/CourseCommerceSettingsForm.php
View source
<?php
namespace Drupal\course_commerce\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CourseCommerceSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('course_uc.settings');
$form['bypass_checkout'] = array(
'#title' => 'Bypass checkout for free course products.',
'#description' => 'Users will not have to go through checkout for course products that are free.',
'#type' => 'checkbox',
'#default_value' => $config
->get('bypass_checkout', TRUE),
);
$form['restrict_qty'] = array(
'#title' => 'Restrict course products to 1 per customer.',
'#description' => 'Course will restrict users from adding the product to cart if they have already purchased the course or already have the course in their cart.',
'#type' => 'checkbox',
'#default_value' => $config
->get('restrict_qty', TRUE),
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable('course_uc.settings')
->setData($form_state
->cleanValues()
->getValues())
->save();
parent::submitForm($form, $form_state);
}
protected function getEditableConfigNames() {
return [
'course_uc.settings',
];
}
public function getFormId() : string {
return 'course_uc_settings_form';
}
}