<?php
function forum_install() {
module_set_weight('forum', 1);
variable_set('node_options_forum', array(
'status',
));
}
function forum_enable() {
$config = config('forum.settings');
$vocabulary = taxonomy_vocabulary_load($config
->get('vocabulary'));
if (!$vocabulary) {
$vocabulary = taxonomy_vocabulary_load('forums');
if (!$vocabulary) {
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => t('Forums'),
'vid' => 'forums',
'langcode' => language_default()->langcode,
'description' => t('Forum navigation vocabulary'),
'hierarchy' => 1,
'module' => 'forum',
'weight' => -10,
));
$vocabulary
->save();
}
$config
->set('vocabulary', $vocabulary
->id())
->save();
}
if (!field_read_field('taxonomy_forums', array(
'include_inactive' => TRUE,
))) {
$field = array(
'field_name' => 'taxonomy_forums',
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary
->id(),
'parent' => 0,
),
),
),
);
field_create_field($field);
$term = entity_create('taxonomy_term', array(
'name' => t('General discussion'),
'langcode' => language_default()->langcode,
'description' => '',
'parent' => array(
0,
),
'vid' => $vocabulary
->id(),
));
$term
->save();
$instance = array(
'field_name' => 'taxonomy_forums',
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'forum',
'required' => TRUE,
);
field_create_instance($instance);
entity_get_form_display('node', 'forum', 'default')
->setComponent('taxonomy_forums', array(
'type' => 'options_select',
))
->save();
entity_get_display('node', 'forum', 'default')
->setComponent('taxonomy_forums', array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
->save();
entity_get_display('node', 'forum', 'teaser')
->setComponent('taxonomy_forums', array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
->save();
}
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['forum']);
}
function forum_uninstall() {
drupal_load('module', 'taxonomy');
variable_del('node_options_forum');
field_delete_field('taxonomy_forums');
field_purge_batch(10);
}
function forum_schema() {
$schema['forum'] = array(
'description' => 'Stores the relationship of nodes to forum terms.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {node}.nid of the node.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: The {node}.vid of the node.',
),
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
),
),
'indexes' => array(
'forum_topic' => array(
'nid',
'tid',
),
'tid' => array(
'tid',
),
),
'primary key' => array(
'vid',
),
'foreign keys' => array(
'forum_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
'vid' => 'vid',
),
),
),
);
$schema['forum_index'] = array(
'description' => 'Maintains denormalized information about node/term relationships.',
'fields' => array(
'nid' => array(
'description' => 'The {node}.nid this record tracks.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'title' => array(
'description' => 'The title of this node, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'tid' => array(
'description' => 'The term ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'created' => array(
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last_comment_timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
),
'comment_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The total number of comments on this node.',
),
),
'indexes' => array(
'forum_topics' => array(
'nid',
'tid',
'sticky',
'last_comment_timestamp',
),
'created' => array(
'created',
),
'last_comment_timestamp' => array(
'last_comment_timestamp',
),
),
'foreign keys' => array(
'tracked_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array(
'tid' => 'tid',
),
),
),
);
return $schema;
}
function forum_update_last_removed() {
return 7003;
}
function forum_update_8000() {
update_variables_to_config('forum.settings', array(
'forum_hot_topic' => 'topics.hot_threshold',
'forum_per_page' => 'topics.page_limit',
'forum_order' => 'topics.order',
'forum_nav_vocabulary' => 'vocabulary',
'forum_containers' => 'containers',
'forum_block_num_active' => 'block.active.limit',
'forum_block_num_new' => 'block.new.limit',
));
}