SqlContentEntityStorageSchema::getFieldForeignKeys

protected SqlContentEntityStorageSchema::getFieldForeignKeys($field_name, array $field_schema, array $column_mapping)

Gets field foreign keys.

Parameters

string $field_name: The name of the field.

array $field_schema: The schema of the field.

string[] $column_mapping: A mapping of field column names to database column names.

Return value

array The schema definition for the foreign keys.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 744

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

protected function getFieldForeignKeys($field_name, array $field_schema, array $column_mapping) {
  $foreign_keys = array();

  foreach ($field_schema['foreign keys'] as $specifier => $specification) {
    // To avoid clashes with entity-level foreign keys we use
    // "{$entity_type_id}_field__" as a prefix instead of just
    // "{$entity_type_id}__". We additionally namespace the specifier by the
    // field name to avoid clashes when multiple fields of the same type are
    // added to an entity type.
    $entity_type_id = $this->entityType->id();
    $real_specifier = "{$entity_type_id}_field__{$field_name}__{$specifier}";
    $foreign_keys[$real_specifier]['table'] = $specification['table'];
    foreach ($specification['columns'] as $column => $referenced) {
      $foreign_keys[$real_specifier]['columns'][$column_mapping[$column]] = $referenced;
    }
  }

  return $foreign_keys;
}
doc_Drupal
2016-10-29 09:43:38
Comments
Leave a Comment

Please login to continue.