public function DDLinesQuestion::getAnsweringForm in Quiz 8.4
Generates the question form.
This is called whenever a question is rendered, either to an administrator or to a quiz taker.
Overrides QuizQuestion::getAnsweringForm
File
- question_types/
quiz_ddlines/ lib/ Drupal/ quiz_ddlines/ DDLinesQuestion.php, line 147 - The main classes for the quiz_ddlines question type.
Class
- DDLinesQuestion
- Extension of QuizQuestion.
Namespace
Drupal\quiz_ddlinesCode
public function getAnsweringForm(array $form_state = NULL, $rid) {
$default_settings = $this
->getDefaultAltSettings();
$default_settings['mode'] = 'take';
drupal_add_js(array(
'quiz_ddlines' => $default_settings,
), 'setting');
$form = parent::getAnsweringForm($form_state, $rid);
$form['helptext'] = array(
'#markup' => t('Answer this question by dragging each rectangular label to the correct circular hotspot.'),
'#weight' => 0,
);
// Form element containing the correct answers
$form['ddlines_elements'] = array(
'#type' => 'hidden',
'#default_value' => isset($this->node->ddlines_elements) ? $this->node->ddlines_elements : '',
);
// Form element containing the user answers
// The quiz module requires this element to be named "tries":
$form['tries'] = array(
'#type' => 'hidden',
'#default_value' => '',
);
$field_image = $this->node->field_image
->getValue();
$uri = $field_image[0]['entity'];
$image_uri = $uri
->getFileUri();
// Image Styling.
$style = entity_load('image_style', 'large');
$image_url = $style
->buildUrl($image_uri);
$form['image'] = array(
'#markup' => '<div class="image-preview">' . theme('image', array(
'uri' => $image_url,
)) . '</div>',
);
_quiz_ddlines_add_js_and_css();
return $form;
}