public function QuizDefaultsForm::buildForm in Quiz 8.6
Same name and namespace in other branches
- 8.5 src/Form/QuizDefaultsForm.php \Drupal\quiz\Form\QuizDefaultsForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ QuizDefaultsForm.php, line 20
Class
Namespace
Drupal\quiz\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('quiz.defaults');
$quiz = Drupal\quiz\Entity\Quiz::create([
'type' => 'quiz',
]);
$entity_type = $quiz
->getEntityType();
$fields = $quiz::baseFieldDefinitions($entity_type);
foreach ($fields as $field_name => $field) {
if (in_array($field_name, [
'qid',
'vid',
'status',
'max_score',
])) {
continue;
}
if ($field
->getType() == 'boolean') {
$form[$field_name] = [
'#title' => $field
->getLabel(),
'#description' => $field
->getDescription(),
'#type' => 'checkbox',
'#default_value' => $config
->get($field_name),
];
}
if ($field
->getType() == 'integer') {
$form[$field_name] = [
'#title' => $field
->getLabel(),
'#description' => $field
->getDescription(),
'#type' => 'number',
'#default_value' => $config
->get($field_name),
];
}
}
return parent::buildForm($form, $form_state);
}