public function ScaleQuestion::getCreationForm in Quiz 8.4
Implementation of getCreationForm
Overrides QuizQuestion::getCreationForm
See also
QuizQuestion#getCreationForm()
File
- question_types/
scale/ lib/ Drupal/ scale/ ScaleQuestion.php, line 393 - The main classes for the short answer question type.
Class
- ScaleQuestion
- Extension of QuizQuestion.
Namespace
Drupal\scaleCode
public function getCreationForm(array &$form_state = NULL) {
drupal_add_js(drupal_get_path('module', 'scale') . '/scale.js');
$form = array();
/*
* Getting presets from the database
*/
$collections = $this
->getPresetCollections(TRUE);
$options = $this
->makeOptions($collections);
$options['d'] = '-';
// Default
// We need to add the available preset collections as javascript so that the alternatives can be populated instantly
// when a
$jsArray = $this
->makeJSArray($collections);
$form['answer'] = array(
'#type' => 'fieldset',
'#title' => t('Answer'),
'#description' => t('Provide alternatives for the user to answer.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -4,
);
$form['answer']['presets'] = array(
'#type' => 'select',
'#title' => t('Presets'),
'#options' => $options,
'#default_value' => 'd',
'#description' => t('Select a set of alternatives'),
'#attributes' => array(
'onchange' => 'refreshAlternatives(this)',
),
);
$max_num_alts = \Drupal::config('scale.settings')
->get('scale_max_num_of_alts');
// TODO: use drupal_add_js($path, 'settings');
$form['jsArray'] = array(
'#markup' => "<script type='text/javascript'>" . $jsArray . "var scale_max_num_of_alts = " . $max_num_alts . ";</script>",
);
$form['answer']['alternatives'] = array(
'#type' => 'fieldset',
'#title' => t('Alternatives'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
for ($i = 0; $i < $max_num_alts; $i++) {
$form['answer']['alternatives']["alternative{$i}"] = array(
'#type' => 'textfield',
'#title' => t('Alternative !i', array(
'!i' => $i + 1,
)),
'#size' => 60,
'#maxlength' => 256,
'#default_value' => isset($this->node->{$i}->answer) ? $this->node->{$i}->answer : '',
'#required' => $i < 2,
);
}
$form['answer']['alternatives']['save'] = array(
// @todo: Rename save to save_as_preset or something
'#type' => 'checkbox',
'#title' => t('Save as a new preset'),
'#description' => t('Current alternatives will be saved as a new preset'),
'#default_value' => FALSE,
);
$form['answer']['manage'] = array(
'#markup' => l(t('Manage presets'), 'scale/collection/manage'),
);
return $form;
}