5 * Install, update, and uninstall functions for the Forum module.
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\taxonomy\Entity\Term;
12 * Implements hook_install().
14 function forum_install() {
15 // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
16 module_set_weight('forum', 1);
17 // Do not allow to delete the forum's node type machine name.
18 $locked = \Drupal::state()->get('node.type.locked');
19 $locked['forum'] = 'forum';
20 \Drupal::state()->set('node.type.locked', $locked);
22 if (!\Drupal::service('config.installer')->isSyncing()) {
23 // Create a default forum so forum posts can be created.
24 $term = Term::create([
25 'name' => t('General discussion'),
29 'forum_container' => 0,
36 * Implements hook_uninstall().
38 function forum_uninstall() {
39 if ($field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums')) {
40 $field_storage->delete();
43 if ($field_storage = FieldStorageConfig::loadByName('node', 'comment_forum')) {
44 $field_storage->delete();
47 if ($field_storage = FieldStorageConfig::loadByName('taxonomy_term', 'forum_container')) {
48 $field_storage->delete();
51 // Purge field data now to allow taxonomy and options module to be uninstalled
52 // if this is the only field remaining.
53 field_purge_batch(10);
54 // Allow to delete a forum's node type.
55 $locked = \Drupal::state()->get('node.type.locked');
56 unset($locked['forum']);
57 \Drupal::state()->set('node.type.locked', $locked);
61 * Implements hook_schema().
63 function forum_schema() {
65 'description' => 'Stores the relationship of nodes to forum terms.',
72 'description' => 'The {node}.nid of the node.',
79 'description' => 'Primary Key: The {node}.vid of the node.',
86 'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
90 'forum_topic' => ['nid', 'tid'],
93 'primary key' => ['vid'],
105 $schema['forum_index'] = [
106 'description' => 'Maintains denormalized information about node/term relationships.',
109 'description' => 'The {node}.nid this record tracks.',
116 'description' => 'The node title.',
123 'description' => 'The term ID.',
130 'description' => 'Boolean indicating whether the node is sticky.',
137 'description' => 'The Unix timestamp when the node was created.',
143 'last_comment_timestamp' => [
147 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
154 'description' => 'The total number of comments on this node.',
158 'forum_topics' => ['nid', 'tid', 'sticky', 'last_comment_timestamp'],
159 'created' => ['created'],
160 'last_comment_timestamp' => ['last_comment_timestamp'],
165 'columns' => ['nid' => 'nid'],
168 'table' => 'taxonomy_term_data',