function FilterEntityReferenceTrait::setUpEntityTypes
Sets up the entity types and relationships.
2 calls to FilterEntityReferenceTrait::setUpEntityTypes()
- FilterEntityReferenceTest::setUp in core/
modules/ views_ui/ tests/ src/ FunctionalJavascript/ FilterEntityReferenceTest.php - FilterEntityReferenceWebTest::setUp in core/
modules/ views_ui/ tests/ src/ Functional/ FilterEntityReferenceWebTest.php - Sets up the test.
File
-
core/
modules/ views_ui/ tests/ src/ Traits/ FilterEntityReferenceTrait.php, line 60
Class
- FilterEntityReferenceTrait
- Sets up the entity types and relationships for entity reference tests.
Namespace
Drupal\Tests\views_ui\TraitsCode
protected function setUpEntityTypes() : void {
// Create an entity type, and a referenceable type. Since these are coded
// into the test view, they are not randomly named.
$this->hostBundle = $this->drupalCreateContentType([
'type' => 'page',
]);
$this->targetBundle = $this->drupalCreateContentType([
'type' => 'article',
]);
$field_storage = FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'node',
],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
]);
$field_storage->save();
$field = FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test',
'bundle' => $this->hostBundle
->id(),
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->targetBundle
->id() => $this->targetBundle
->label(),
],
],
],
]);
$field->save();
// Create 10 nodes for use as target entities.
for ($i = 0; $i < 10; $i++) {
$node = $this->drupalCreateNode([
'type' => $this->targetBundle
->id(),
'title' => ucfirst($this->targetBundle
->id()) . ' ' . $i,
]);
$this->targetEntities[$node->id()] = $node;
}
// Create 1 host entity to reference target entities from.
$node = $this->drupalCreateNode([
'type' => $this->hostBundle
->id(),
'title' => ucfirst($this->hostBundle
->id()) . ' 0',
]);
$this->hostEntities = [
$node->id() => $node,
];
$field_storage = FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test_config',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'node_type',
],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
]);
$field_storage->save();
$field = FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test_config',
'bundle' => $this->hostBundle
->id(),
'settings' => [
'handler' => 'default',
'handler_settings' => [
'sort' => [
'field' => '_none',
],
],
],
]);
$field->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.