function EntitySchemaTest::findPrimaryKeys
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::findPrimaryKeys()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::findPrimaryKeys()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::findPrimaryKeys()
Finds the primary keys for a given entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type whose primary keys are being fetched.
Return value
array[] An array where the keys are the table names of the entity type's tables and the values are a list of the respective primary keys.
1 call to EntitySchemaTest::findPrimaryKeys()
- EntitySchemaTest::testPrimaryKeyUpdate in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntitySchemaTest.php - Tests deleting and creating a field that is part of a primary key.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntitySchemaTest.php, line 240
Class
- EntitySchemaTest
- Tests the default entity storage schema handler.
Namespace
Drupal\KernelTests\Core\EntityCode
protected function findPrimaryKeys(EntityTypeInterface $entity_type) {
$base_table = $entity_type->getBaseTable();
$revision_table = $entity_type->getRevisionTable();
$data_table = $entity_type->getDataTable();
$revision_data_table = $entity_type->getRevisionDataTable();
$schema = $this->database
->schema();
$find_primary_key_columns = new \ReflectionMethod(get_class($schema), 'findPrimaryKeyColumns');
// Build up a map of primary keys depending on the entity type
// configuration. If the field that is being removed is part of a table's
// primary key, we skip the assertion for that table as this represents an
// intermediate and invalid state of the entity schema.
$primary_keys[$base_table] = $find_primary_key_columns->invoke($schema, $base_table);
if ($entity_type->isRevisionable()) {
$primary_keys[$revision_table] = $find_primary_key_columns->invoke($schema, $revision_table);
}
if ($entity_type->isTranslatable()) {
$primary_keys[$data_table] = $find_primary_key_columns->invoke($schema, $data_table);
}
if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
$primary_keys[$revision_data_table] = $find_primary_key_columns->invoke($schema, $revision_data_table);
}
return $primary_keys;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.