drupal/core/modules/entity_reference/entity_reference.install

49 lines
1.3 KiB
Plaintext

<?php
/**
* @file
* Install, update and uninstall functions for the Entity Reference
* module.
*/
/**
* Implements hook_field_schema().
*/
function entity_reference_field_schema($field) {
$schema = array(
'columns' => array(
'target_id' => array(
'description' => 'The ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'revision_id' => array(
'description' => 'The revision ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'target_id' => array('target_id'),
),
);
// Create a foreign key to the target entity type base type.
$entity_manager = Drupal::service('plugin.manager.entity');
if (is_subclass_of($entity_manager->getControllerClass($field['settings']['target_type'], 'storage'), 'Drupal\Core\Entity\DatabaseStorageController')) {
$entity_info = $entity_manager->getDefinition($field['settings']['target_type']);
$base_table = $entity_info['base_table'];
$id_column = $entity_info['entity_keys']['id'];
$schema['foreign keys'][$base_table] = array(
'table' => $base_table,
'columns' => array('target_id' => $id_column),
);
}
return $schema;
}