entity_usage.install in Entity Usage 8
Same filename and directory in other branches
Install, update and uninstall functions for entity_usage module.
File
entity_usage.installView source
<?php
/**
* @file
* Install, update and uninstall functions for entity_usage module.
*/
/**
* Implements hook_schema().
*/
function entity_usage_schema() {
$schema['entity_usage'] = [
'description' => 'Track entities that reference other entities.',
'fields' => [
't_id' => [
'description' => 'Target entity ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
't_type' => [
'description' => 'The type of the target entity.',
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
],
're_id' => [
'description' => 'Referencing entity ID.',
'type' => 'varchar_ascii',
'length' => 64,
'not null' => TRUE,
'default' => 0,
],
're_type' => [
'description' => 'The type of the referencing entity.',
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
],
'method' => [
'description' => 'The method used to reference both entities, generally the plugin ID.',
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
],
'count' => [
'description' => 'The number of times this entity is referenced in this case.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => [
't_id',
't_type',
're_id',
're_type',
'method',
],
'indexes' => [
'ttype_tid' => [
't_type',
't_id',
],
'tid_ttype_count' => [
't_id',
't_type',
'count',
],
],
];
return $schema;
}
/**
* Include "method" also as primary key for the {entity_usage} table.
*/
function entity_usage_update_8001(&$sandbox) {
$database = \Drupal::database();
$database
->schema()
->dropPrimaryKey('entity_usage');
$new_primary_keys = [
't_id',
't_type',
're_id',
're_type',
'method',
];
$database
->schema()
->addPrimaryKey('entity_usage', $new_primary_keys);
}
Functions
Name | Description |
---|---|
entity_usage_schema | Implements hook_schema(). |
entity_usage_update_8001 | Include "method" also as primary key for the {entity_usage} table. |