function quiz_question_add_body_field in Quiz 7.5
Same name and namespace in other branches
- 7.6 question_types/quiz_question/quiz_question.module \quiz_question_add_body_field()
- 7 question_types/quiz_question/quiz_question.module \quiz_question_add_body_field()
- 7.4 question_types/quiz_question/quiz_question.module \quiz_question_add_body_field()
Add body field to quiz_question nodes.
Parameters
string $type: The question content type machine name.
8 calls to quiz_question_add_body_field()
- long_answer_install in question_types/
long_answer/ long_answer.install - Implements hook_install().
- matching_install in question_types/
matching/ matching.install - Implements hook_install().
- multichoice_install in question_types/
multichoice/ multichoice.install - Implements hook_install().
- quiz_directions_install in question_types/
quiz_directions/ quiz_directions.install - Implements hook_install().
- quiz_page_install in question_types/
quiz_page/ quiz_page.install - Implements hook_install().
File
- question_types/
quiz_question/ quiz_question.module, line 718 - Quiz Question module.
Code
function quiz_question_add_body_field($type) {
node_types_rebuild();
$node_type = node_type_get_type($type);
if (!$node_type) {
watchdog('quiz', 'Attempt to add body field was failed as question content type %type is not defined.', array(
'%type' => $type,
), WATCHDOG_ERROR);
watchdog('quiz', '<pre>' . print_r(node_type_get_types(), 1), array(), WATCHDOG_ERROR);
return;
}
node_add_body_field($node_type, 'Question');
// Override default weight to make body field appear first.
$instance = field_read_instance('node', 'body', $type);
$instance['widget']['weight'] = -10;
$instance['widget']['settings']['rows'] = 6;
// Make the question body visible by default for the question view mode.
$instance['display']['question'] = array(
'label' => 'hidden',
'type' => 'text_default',
'weight' => 1,
'settings' => array(),
'module' => 'text',
);
field_update_instance($instance);
}