function answers_install in Answers 7.4
Same name and namespace in other branches
- 8 answers.install \answers_install()
- 5.2 answers.install \answers_install()
Implements hook_install().
Defines question and answer content types and entityreference field to relate each answer with its question.
File
- ./
answers.install, line 14 - Install, update, and uninstall functions for the answers module.
Code
function answers_install() {
$t = get_t();
// Get the answer_question and answers_answer node types.
node_types_rebuild();
$types = node_type_get_types();
// Set up the answers_question node type.
node_add_body_field($types['answers_question'], $t('Body'));
$body_instance = field_info_instance('node', 'body', 'answers_question');
$body_instance['display']['default']['label'] = 'hidden';
$body_instance['settings']['display_summary'] = 0;
$body_instance['widget']['settings']['rows'] = 15;
field_update_instance($body_instance);
foreach (_answers_question_installed_fields() as $field) {
field_create_field($field);
}
foreach (_answers_question_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'answers_question';
field_create_instance($instance);
}
// Set up the answers_answer node type.
node_add_body_field($types['answers_answer'], $t('Body'));
$body_instance = field_info_instance('node', 'body', 'answers_answer');
$body_instance['required'] = TRUE;
$body_instance['display']['default'] = array(
'label' => 'hidden',
'type' => 'text_default',
'module' => 'text',
);
$body_instance['settings']['display_summary'] = 0;
$body_instance['widget']['settings']['rows'] = 15;
field_update_instance($body_instance);
foreach (_answers_answer_installed_fields() as $field) {
field_create_field($field);
}
foreach (_answers_answer_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'answers_answer';
field_create_instance($instance);
}
field_cache_clear();
_answers_enable_permissions();
// TODO: extract comment and the rest of vars.
variable_set('node_preview_answers_question', 0);
variable_set('node_options_answers_question', array(
'status',
));
variable_set('menu_options_answers_question', array());
variable_set('comment_answers_question', 2);
variable_set('comment_default_mode_answers_question', 0);
variable_set('comment_preview_answers_question', 0);
variable_set('comment_subject_field_answers_question', 0);
variable_set('node_preview_answers_answer', 0);
variable_set('node_options_answers_answer', array(
'status',
));
variable_set('menu_options_answers_answer', array());
variable_set('comment_answers_answer', 2);
variable_set('comment_default_mode_answers_answer', 0);
variable_set('comment_preview_answers_answer', 0);
variable_set('comment_subject_field_answers_answer', 0);
}