function EntityReferenceAdminTest::createEntityReferenceField

Same name and namespace in other branches
  1. 8.9.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
  2. 10 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::createEntityReferenceField()
  3. 11.x 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 377

Class

EntityReferenceAdminTest
Tests for the administrative UI.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.