public function ClozeQuestion::getAnsweringForm in Cloze 7
Same name and namespace in other branches
- 6 cloze.classes.inc \ClozeQuestion::getAnsweringForm()
Implementation of getAnsweringForm
See also
QuizQuestion#getAnsweringForm($form_state, $rid)
File
- ./
cloze.classes.inc, line 149 - The main classes for the cloze question type. These inherit or implement code found in quiz_question.classes.inc.
Class
- ClozeQuestion
- Extension of QuizQuestion.
Code
public function getAnsweringForm(array $form_state = NULL, $rid) {
$form = parent::getAnsweringForm($form_state, $rid);
$form['#theme'] = 'cloze_answering_form';
$module_path = drupal_get_path('module', 'cloze');
if (isset($this->node->learning_mode) && $this->node->learning_mode) {
$form['#attached']['js'][] = $module_path . '/theme/cloze.js';
$question = $form['question']['#markup'];
$this
->_answerJs($question);
}
$form['#attached']['css'][] = $module_path . '/theme/cloze.css';
$form['open_wrapper'] = array(
'#markup' => '<div class="cloze-question">',
);
foreach (_cloze_get_question_chunks($this->node->body[LANGUAGE_NONE]['0']['value']) as $position => $chunk) {
if (strpos($chunk, '[') === FALSE) {
// this "tries[foobar]" hack is needed becaues question handler engine checks for input field
// with name tries
$form['tries[' . $position . ']'] = array(
'#markup' => str_replace("\n", "<br/>", $chunk),
'#prefix' => '<div class="form-item">',
'#suffix' => '</div>',
);
}
else {
$chunk = str_replace(array(
'[',
']',
), '', $chunk);
$choices = explode(',', $chunk);
if (count($choices) > 1) {
$form['tries[' . $position . ']'] = array(
'#type' => 'select',
'#title' => '',
'#options' => _cloze_shuffle_choices(drupal_map_assoc($choices)),
'#required' => FALSE,
);
}
else {
$form['tries[' . $position . ']'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => 32,
'#required' => FALSE,
'#attributes' => array(
'autocomplete' => 'off',
'class' => array(
'answer-' . $position,
),
),
);
}
}
}
$form['close_wrapper'] = array(
'#markup' => '</div>',
);
if (isset($rid)) {
$cloze_esponse = new ClozeResponse($rid, $this->node);
$response = $cloze_esponse
->getResponse();
if (is_array($response)) {
foreach ($response as $key => $value) {
$form["tries[{$key}]"]['#default_value'] = $value;
}
}
}
return $form;
}