You are here

protected function NodeImportTest::setupTaxonomyField in YAML Content 8

Helper to fill out the tags taxonomy field from the standard profile.

1 call to NodeImportTest::setupTaxonomyField()
NodeImportTest::testFancyNode in tests/src/Functional/NodeImportTest.php

File

tests/src/Functional/NodeImportTest.php, line 128

Class

NodeImportTest
Tests general Node creation functionality.

Namespace

Drupal\Tests\yaml_content\Functional

Code

protected function setupTaxonomyField() {

  // Create tags reference field.
  $field_name = 'field_tags';
  $handler_settings = [
    'target_bundles' => [
      'tags' => 'tags',
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $entity_type_manager
    ->getStorage('entity_form_display')
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_autocomplete_tags',
    'weight' => -4,
  ])
    ->save();
}