protected function EnforcedIntegrityTest::createDependentEntity in Entity Reference Integrity 8
Create an entity that depends on the given entity.
1 call to EnforcedIntegrityTest::createDependentEntity()
- EnforcedIntegrityTest::assertEntityDeleteProtected in modules/
entity_reference_integrity_enforce/ tests/ src/ Functional/ EnforcedIntegrityTest.php - Check that the delete form of an entity is protected.
File
- modules/
entity_reference_integrity_enforce/ tests/ src/ Functional/ EnforcedIntegrityTest.php, line 127
Class
- EnforcedIntegrityTest
- Test enforcing referential integrity.
Namespace
Drupal\Tests\entity_reference_integrity_enforce\FunctionalCode
protected function createDependentEntity(EntityInterface $entity) {
// Create a bundle with the name name as the target entity type ID and an
// entity reference field to link the two.
entity_test_create_bundle($entity
->getEntityTypeId());
FieldStorageConfig::create([
'field_name' => 'test_reference_field',
'entity_type' => 'entity_test',
'type' => 'entity_reference',
'settings' => [
'target_type' => $entity
->getEntityTypeId(),
],
])
->save();
FieldConfig::create([
'field_name' => 'test_reference_field',
'entity_type' => 'entity_test',
'bundle' => $entity
->getEntityTypeId(),
'label' => 'Reference Field',
])
->save();
$dependent = EntityTest::create([
'name' => $this
->randomMachineName(),
'type' => $entity
->getEntityTypeId(),
'test_reference_field' => [
'entity' => $entity,
],
]);
$dependent
->save();
return $dependent;
}