comment.install
Same filename and directory in other branches
Install, update and uninstall functions for the Comment module.
File
-
core/
modules/ comment/ comment.install
View source
<?php
/**
* @file
* Install, update and uninstall functions for the Comment module.
*/
use Drupal\Core\Database\SchemaDefinition\Column;
use Drupal\Core\Database\SchemaDefinition\ColumnSize;
use Drupal\Core\Database\SchemaDefinition\ForeignKey;
use Drupal\Core\Database\SchemaDefinition\Index;
use Drupal\Core\Database\SchemaDefinition\IntValue;
use Drupal\Core\Database\SchemaDefinition\PrimaryKey;
use Drupal\Core\Database\SchemaDefinition\Schema;
use Drupal\Core\Database\SchemaDefinition\SchemaDefinitionType;
use Drupal\Core\Database\SchemaDefinition\StringValue;
use Drupal\Core\Database\SchemaDefinition\Table;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_uninstall().
*/
function comment_uninstall() : void {
// Remove the comment fields.
$storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
$fields = $storage->loadByProperties([
'type' => 'comment',
]);
$storage->delete($fields);
// Remove state setting.
\Drupal::state()->delete('comment.node_comment_statistics_scale');
}
/**
* Implements hook_install().
*/
function comment_install() : void {
// By default, maintain entity statistics for comments.
// @see \Drupal\comment\CommentStatisticsInterface
\Drupal::state()->set('comment.maintain_entity_statistics', TRUE);
}
/**
* Implements hook_schema().
*/
function comment_schema() : Schema {
$tables[] = new Table(name: 'comment_entity_statistics', description: 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.', columns: [
Column::int(name: 'entity_id', description: 'The entity_id of the entity for which the statistics are compiled.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::varcharAscii(name: 'entity_type', description: 'The entity_type of the entity to which this comment is a reply.', length: EntityTypeInterface::ID_MAX_LENGTH, notNull: TRUE, default: new StringValue('node')),
Column::varcharAscii(name: 'field_name', description: 'The field_name of the field that was used to add this comment.', length: FieldStorageConfig::NAME_MAX_LENGTH, notNull: TRUE, default: new StringValue('')),
Column::int(name: 'cid', description: 'The {comment}.cid of the last comment.', notNull: TRUE, default: new IntValue(0)),
Column::int(name: 'last_comment_timestamp', description: 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.', size: ColumnSize::Big, notNull: TRUE, default: new IntValue(0)),
Column::varchar(name: 'last_comment_name', description: 'The name of the latest author to post a comment on this node, from {comment}.name.', length: 60, notNull: FALSE),
Column::int(name: 'last_comment_uid', description: 'The user ID of the latest author to post a comment on this node, from {comment}.uid.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::int(name: 'comment_count', description: 'The total number of comments on this entity.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
], primaryKey: new PrimaryKey([
'entity_id',
'entity_type',
'field_name',
]), indexes: [
new Index(name: 'last_comment_timestamp', columns: [
'last_comment_timestamp',
]),
new Index(name: 'comment_count', columns: [
'comment_count',
]),
new Index(name: 'last_comment_uid', columns: [
'last_comment_uid',
]),
], foreignKeys: [
new ForeignKey(name: 'last_comment_author', foreignTable: 'users', columns: [
'last_comment_uid',
], foreignColumns: [
'uid',
]),
]);
return new Schema(type: SchemaDefinitionType::Module, name: 'comment', tables: $tables);
}
/**
* Implements hook_update_last_removed().
*/
function comment_update_last_removed() : int {
return 10100;
}
Functions
| Title | Deprecated | Summary |
|---|---|---|
| comment_install | Implements hook_install(). | |
| comment_schema | Implements hook_schema(). | |
| comment_uninstall | Implements hook_uninstall(). | |
| comment_update_last_removed | Implements hook_update_last_removed(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.