You are here

protected function TaxonomyPermissionsTestBase::attachFields in Taxonomy Permissions 8

Helper function to create and attach a field to a node.

Parameters

string $field_name: The field name to create and attach.

1 call to TaxonomyPermissionsTestBase::attachFields()
TaxonomyPermissionsTestBase::setUp in src/Tests/TaxonomyPermissionsTestBase.php
Setup.

File

src/Tests/TaxonomyPermissionsTestBase.php, line 326

Class

TaxonomyPermissionsTestBase
General setup and helper function for testing taxonomy permissions module.

Namespace

Drupal\taxonomy_permissions\Tests

Code

protected function attachFields($field_name) {

  // Add a field to the article content type which reference term.
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => FALSE,
  ];
  $this
    ->createField('node', 'article', $field_name, 'Term referenced', 'taxonomy_term', 'default', $handler_settings);

  // Set the form display.
  $settings = [
    'match_operator' => 'CONTAINS',
    'size' => 30,
    'placeholder' => '',
  ];
  $this
    ->setFormDisplay('node.article.default', 'node', 'article', $field_name, 'entity_reference_autocomplete', $settings);

  // Set the view display.
  $settings = [
    'link' => TRUE,
  ];
  $this
    ->setViewDisplay('node.article.default', 'node', 'article', $field_name, 'entity_reference_label', $settings);
}