protected function EntityReferenceAdminTest::createEntityReferenceField in Drupal 8
Same name and namespace in other branches
- 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
Creates a new Entity Reference fields with a given target type.
Parameters
string $target_type: The name of the target type
string[] $bundles: A list of bundle IDs. Defaults to [].
Return value
string Returns the generated field name
3 calls to EntityReferenceAdminTest::createEntityReferenceField()
- EntityReferenceAdminTest::testAvailableFormatters in core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php - Tests the formatters for the Entity References.
- EntityReferenceAdminTest::testFieldAdminHandler in core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php - Tests the Entity Reference Admin UI.
- EntityReferenceAdminTest::testMultipleTargetBundles in core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php - Tests field settings for an entity reference field when the field has multiple target bundles and is set to auto-create the target entity.
File
- core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php, line 365
Class
- EntityReferenceAdminTest
- Tests for the administrative UI.
Namespace
Drupal\Tests\field\Functional\EntityReferenceCode
protected function createEntityReferenceField($target_type, $bundles = []) {
// Generates a bundle path for the newly created content type.
$bundle_path = 'admin/structure/types/manage/' . $this->type;
// Generate a random field name, must be only lowercase characters.
$field_name = strtolower($this
->randomMachineName());
$storage_edit = $field_edit = [];
$storage_edit['settings[target_type]'] = $target_type;
foreach ($bundles as $bundle) {
$field_edit['settings[handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
}
$this
->fieldUIAddNewField($bundle_path, $field_name, NULL, 'entity_reference', $storage_edit, $field_edit);
// Returns the generated field name.
return $field_name;
}