truefalse.module in Quiz 8.4
Same filename and directory in other branches
TrueFalse question type for quiz module
Allows the creation of "True or False" questions
File
question_types/truefalse/truefalse.moduleView source
<?php
/**
* @file
* TrueFalse question type for quiz module
*
* Allows the creation of "True or False" questions
*/
/**
* Implements hook_help().
*/
function truefalse_help($path, $args) {
switch ($path) {
case 'admin/modules#description':
return t('TrueFalse question type for the quiz module.');
case 'node/add#truefalse':
case 'admin/help#truefalse':
return t('A question type for the quiz module. A simplified version of multichoice where "true" and "false" are the alternatives.');
default:
break;
}
}
/**
* Implements hook_quiz_question_info().
*/
function truefalse_quiz_question_info() {
$config = \Drupal::config('node.type.truefalse');
return array(
'truefalse' => array(
'name' => $config
->get('name'),
'description' => $config
->get('description'),
'question provider' => 'Drupal\\truefalse\\TrueFalseQuestion',
'response provider' => 'Drupal\\truefalse\\TrueFalseResponse',
'module' => 'quiz_question',
),
);
}
/**
* Implements hook_config().
*/
function truefalse_config() {
return FALSE;
}
/**
* Implements hook_theme().
*/
function truefalse_theme() {
return array(
'truefalse_response' => array(
'variables' => array(
'metadata' => array(),
'data' => array(),
),
),
);
}
/**
* Theme the response part of the response report
*
* @param $metadata
* Can be used as a table header
* @param $data
* Can be used as table rows
*/
function theme_truefalse_response($variables) {
$metadata = $variables['metadata'];
$data = $variables['data'];
return theme('table', array(
'header' => $metadata,
'rows' => $data,
));
}
/**
* Implements hook_field_extra_fields().
*/
function truefalse_field_extra_fields() {
$extra = array();
foreach (node_type_get_types() as $bundle_name => $bundle) {
if ($bundle_name == 'truefalse') {
$extra['node'][$bundle->type]['form']['correct_answer'] = array(
'label' => t('Correct answer'),
'description' => t('The answer for this question.'),
'weight' => -4,
);
$extra['node'][$bundle->type]['form']['feedback_fields'] = array(
'label' => t('Feedback Settings'),
'description' => t('Settings pertaining to feedback given along with results.'),
'weight' => -4,
);
}
}
return $extra;
}
Functions
Name | Description |
---|---|
theme_truefalse_response | Theme the response part of the response report |
truefalse_config | Implements hook_config(). |
truefalse_field_extra_fields | Implements hook_field_extra_fields(). |
truefalse_help | Implements hook_help(). |
truefalse_quiz_question_info | Implements hook_quiz_question_info(). |
truefalse_theme | Implements hook_theme(). |