public function EntityReferenceAdminTest::createEntityReferenceField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
Creates a new Entity Reference fields with a given target type.
Parameters
$target_type: The name of the target type
$bundle: Name of the bundle Default = NULL
Return value
string Returns the generated field name
2 calls to EntityReferenceAdminTest::createEntityReferenceField()
- EntityReferenceAdminTest::testAvailableFormatters in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceAdminTest.php - Tests the formatters for the Entity References.
- EntityReferenceAdminTest::testFieldAdminHandler in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceAdminTest.php - Tests the Entity Reference Admin UI.
File
- core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceAdminTest.php, line 399 - Contains \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest.
Class
- EntityReferenceAdminTest
- Tests for the administrative UI.
Namespace
Drupal\field\Tests\EntityReferenceCode
public function createEntityReferenceField($target_type, $bundle = NULL) {
// 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 = array();
$storage_edit['settings[target_type]'] = $target_type;
if ($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;
}