protected function ShsTestTrait::prepareSetup in Simple hierarchical select 2.0.x
Prepares test setup by creating a content type with the necessary fields.
Parameters
string $field_name: Name of field to create.
int $cardinality: The field cardinality.
1 call to ShsTestTrait::prepareSetup()
- ShsTestBase::setUp in tests/
src/ Functional/ ShsTestBase.php
File
- tests/
src/ Functional/ ShsTestTrait.php, line 47
Class
- ShsTestTrait
- Base test class for SHS browser tests.
Namespace
Drupal\Tests\shs\FunctionalCode
protected function prepareSetup($field_name, int $cardinality = 1) : void {
// Create article content type.
if ($this->profile != 'standard') {
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
}
// Create a vocabulary.
$this->vocabulary = $this
->createVocabulary();
FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => $cardinality,
'settings' => [
'target_type' => 'taxonomy_term',
],
])
->save();
FieldConfig::create([
'field_name' => $field_name,
'bundle' => 'article',
'entity_type' => 'node',
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
],
],
])
->save();
// Configure the form widget.
EntityFormDisplay::load('node.article.default')
->setComponent($field_name, [
'type' => 'options_shs',
])
->save();
// Configure display settings.
EntityViewDisplay::load('node.article.default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
->save();
// Create terms.
$this
->createTerms();
}