function EntityReferenceAdminTest::createEntityReferenceField
Same name in other branches
- 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
- 8.9.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
- 10 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.
File
-
core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php, line 394
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 = $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, $field_name, 'entity_reference', $storage_edit, $field_edit);
// Returns the generated field name.
return $field_name;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.