public function DomainEntityReferenceTest::domainCreateTestField in Domain Access 8
Creates a simple field for testing on the article content type.
Note: This code is a model for auto-creation of fields.
2 calls to DomainEntityReferenceTest::domainCreateTestField()
- DomainEntityReferenceTest::testDomainField in domain/
tests/ src/ Functional/ DomainEntityReferenceTest.php - Create, edit and delete a domain field via the user interface.
- DomainEntityReferenceTest::testDomainFieldStorage in domain/
tests/ src/ Functional/ DomainEntityReferenceTest.php - Create content for a domain field.
File
- domain/
tests/ src/ Functional/ DomainEntityReferenceTest.php, line 124
Class
- DomainEntityReferenceTest
- Tests the domain record entity reference field type.
Namespace
Drupal\Tests\domain\FunctionalCode
public function domainCreateTestField() {
$label = 'domain';
$name = 'field_' . $label;
$storage = [
'field_name' => $name,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => -1,
'settings' => [
'target_type' => 'domain',
],
];
$field_storage_config = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->create($storage);
$field_storage_config
->save();
$field = [
'field_name' => $name,
'entity_type' => 'node',
'label' => 'Domain test field',
'bundle' => 'article',
'settings' => [
'handler_settings' => [
'sort' => [
'field' => 'weight',
'direction' => 'ASC',
],
],
],
];
$field_config = \Drupal::entityTypeManager()
->getStorage('field_config')
->create($field);
$field_config
->save();
// Tell the form system how to behave.
if ($display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('node.article.default')) {
$display
->setComponent($name, [
'type' => 'options_buttons',
])
->save();
}
}