protected function EckEntityTest::createEckEntityType in Entity Construction Kit (ECK) 8
Creates ECK entity type.
Return value
\Drupal\eck\Entity\EckEntityType
1 call to EckEntityTest::createEckEntityType()
- EckEntityTest::testEckMethods in tests/
src/ Kernel/ EckEntityTest.php - Tests some of the ECK entity methods.
File
- tests/
src/ Kernel/ EckEntityTest.php, line 66
Class
- EckEntityTest
- Tests the ECK entity class.
Namespace
Drupal\Tests\eck\KernelCode
protected function createEckEntityType($id, $base_fields = []) {
$entity_type = EckEntityType::create([
'id' => $id,
'label' => $this
->randomString(),
]);
$entity_type
->save();
// Create bundle with the same ID.
EckEntityBundle::create([
'id' => $id,
'type' => $this
->randomString(),
]);
// Add requested base fields.
$allowed_base_fields = [
'created',
'changed',
'uid',
'title',
'status',
];
$enabled_fields = array_intersect($base_fields, $allowed_base_fields);
$config = \Drupal::configFactory()
->getEditable('eck.eck_entity_type.' . $entity_type
->id());
foreach ($enabled_fields as $field_name) {
$config
->set($field_name, TRUE);
}
$config
->save();
// Clear entity definitions cache to find definition of our new entity type.
\Drupal::entityTypeManager()
->clearCachedDefinitions();
return $entity_type;
}