annotate core/modules/forum/forum.install @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Install, update, and uninstall functions for the Forum module.
Chris@0 6 */
Chris@0 7
Chris@0 8 use Drupal\field\Entity\FieldStorageConfig;
Chris@0 9 use Drupal\taxonomy\Entity\Term;
Chris@0 10
Chris@0 11 /**
Chris@0 12 * Implements hook_install().
Chris@0 13 */
Chris@0 14 function forum_install() {
Chris@0 15 // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
Chris@0 16 module_set_weight('forum', 1);
Chris@0 17 // Do not allow to delete the forum's node type machine name.
Chris@0 18 $locked = \Drupal::state()->get('node.type.locked');
Chris@0 19 $locked['forum'] = 'forum';
Chris@0 20 \Drupal::state()->set('node.type.locked', $locked);
Chris@0 21
Chris@0 22 if (!\Drupal::service('config.installer')->isSyncing()) {
Chris@0 23 // Create a default forum so forum posts can be created.
Chris@0 24 $term = Term::create([
Chris@0 25 'name' => t('General discussion'),
Chris@0 26 'description' => '',
Chris@0 27 'parent' => [0],
Chris@0 28 'vid' => 'forums',
Chris@0 29 'forum_container' => 0,
Chris@0 30 ]);
Chris@0 31 $term->save();
Chris@0 32 }
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Implements hook_uninstall().
Chris@0 37 */
Chris@0 38 function forum_uninstall() {
Chris@0 39 if ($field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums')) {
Chris@0 40 $field_storage->delete();
Chris@0 41 }
Chris@0 42
Chris@0 43 if ($field_storage = FieldStorageConfig::loadByName('node', 'comment_forum')) {
Chris@0 44 $field_storage->delete();
Chris@0 45 }
Chris@0 46
Chris@0 47 if ($field_storage = FieldStorageConfig::loadByName('taxonomy_term', 'forum_container')) {
Chris@0 48 $field_storage->delete();
Chris@0 49 }
Chris@0 50
Chris@0 51 // Purge field data now to allow taxonomy and options module to be uninstalled
Chris@0 52 // if this is the only field remaining.
Chris@0 53 field_purge_batch(10);
Chris@0 54 // Allow to delete a forum's node type.
Chris@0 55 $locked = \Drupal::state()->get('node.type.locked');
Chris@0 56 unset($locked['forum']);
Chris@0 57 \Drupal::state()->set('node.type.locked', $locked);
Chris@0 58 }
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Implements hook_schema().
Chris@0 62 */
Chris@0 63 function forum_schema() {
Chris@0 64 $schema['forum'] = [
Chris@0 65 'description' => 'Stores the relationship of nodes to forum terms.',
Chris@0 66 'fields' => [
Chris@0 67 'nid' => [
Chris@0 68 'type' => 'int',
Chris@0 69 'unsigned' => TRUE,
Chris@0 70 'not null' => TRUE,
Chris@0 71 'default' => 0,
Chris@0 72 'description' => 'The {node}.nid of the node.',
Chris@0 73 ],
Chris@0 74 'vid' => [
Chris@0 75 'type' => 'int',
Chris@0 76 'unsigned' => TRUE,
Chris@0 77 'not null' => TRUE,
Chris@0 78 'default' => 0,
Chris@0 79 'description' => 'Primary Key: The {node}.vid of the node.',
Chris@0 80 ],
Chris@0 81 'tid' => [
Chris@0 82 'type' => 'int',
Chris@0 83 'unsigned' => TRUE,
Chris@0 84 'not null' => TRUE,
Chris@0 85 'default' => 0,
Chris@0 86 'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
Chris@0 87 ],
Chris@0 88 ],
Chris@0 89 'indexes' => [
Chris@0 90 'forum_topic' => ['nid', 'tid'],
Chris@0 91 'tid' => ['tid'],
Chris@0 92 ],
Chris@0 93 'primary key' => ['vid'],
Chris@0 94 'foreign keys' => [
Chris@0 95 'forum_node' => [
Chris@0 96 'table' => 'node',
Chris@0 97 'columns' => [
Chris@0 98 'nid' => 'nid',
Chris@0 99 'vid' => 'vid',
Chris@0 100 ],
Chris@0 101 ],
Chris@0 102 ],
Chris@0 103 ];
Chris@0 104
Chris@0 105 $schema['forum_index'] = [
Chris@0 106 'description' => 'Maintains denormalized information about node/term relationships.',
Chris@0 107 'fields' => [
Chris@0 108 'nid' => [
Chris@0 109 'description' => 'The {node}.nid this record tracks.',
Chris@0 110 'type' => 'int',
Chris@0 111 'unsigned' => TRUE,
Chris@0 112 'not null' => TRUE,
Chris@0 113 'default' => 0,
Chris@0 114 ],
Chris@0 115 'title' => [
Chris@0 116 'description' => 'The node title.',
Chris@0 117 'type' => 'varchar',
Chris@0 118 'length' => 255,
Chris@0 119 'not null' => TRUE,
Chris@0 120 'default' => '',
Chris@0 121 ],
Chris@0 122 'tid' => [
Chris@0 123 'description' => 'The term ID.',
Chris@0 124 'type' => 'int',
Chris@0 125 'unsigned' => TRUE,
Chris@0 126 'not null' => TRUE,
Chris@0 127 'default' => 0,
Chris@0 128 ],
Chris@0 129 'sticky' => [
Chris@0 130 'description' => 'Boolean indicating whether the node is sticky.',
Chris@0 131 'type' => 'int',
Chris@0 132 'not null' => FALSE,
Chris@0 133 'default' => 0,
Chris@0 134 'size' => 'tiny',
Chris@0 135 ],
Chris@0 136 'created' => [
Chris@0 137 'description' => 'The Unix timestamp when the node was created.',
Chris@0 138 'type' => 'int',
Chris@0 139 'unsigned' => TRUE,
Chris@0 140 'not null' => TRUE,
Chris@0 141 'default' => 0,
Chris@0 142 ],
Chris@0 143 'last_comment_timestamp' => [
Chris@0 144 'type' => 'int',
Chris@0 145 'not null' => TRUE,
Chris@0 146 'default' => 0,
Chris@0 147 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
Chris@0 148 ],
Chris@0 149 'comment_count' => [
Chris@0 150 'type' => 'int',
Chris@0 151 'unsigned' => TRUE,
Chris@0 152 'not null' => TRUE,
Chris@0 153 'default' => 0,
Chris@0 154 'description' => 'The total number of comments on this node.',
Chris@0 155 ],
Chris@0 156 ],
Chris@0 157 'indexes' => [
Chris@0 158 'forum_topics' => ['nid', 'tid', 'sticky', 'last_comment_timestamp'],
Chris@0 159 'created' => ['created'],
Chris@0 160 'last_comment_timestamp' => ['last_comment_timestamp'],
Chris@0 161 ],
Chris@0 162 'foreign keys' => [
Chris@0 163 'tracked_node' => [
Chris@0 164 'table' => 'node',
Chris@0 165 'columns' => ['nid' => 'nid'],
Chris@0 166 ],
Chris@0 167 'term' => [
Chris@0 168 'table' => 'taxonomy_term_data',
Chris@0 169 'columns' => [
Chris@0 170 'tid' => 'tid',
Chris@0 171 ],
Chris@0 172 ],
Chris@0 173 ],
Chris@0 174 ];
Chris@0 175
Chris@0 176 return $schema;
Chris@0 177 }