You are here

protected function SitemapTaxonomyTestBase::addEntityreferenceField in Sitemap 8

Same name and namespace in other branches
  1. 8.2 src/Tests/SitemapTaxonomyTestBase.php \Drupal\sitemap\Tests\SitemapTaxonomyTestBase::addEntityreferenceField()
  2. 2.0.x src/Tests/SitemapTaxonomyTestBase.php \Drupal\sitemap\Tests\SitemapTaxonomyTestBase::addEntityreferenceField()

Add an entityreference field to tag nodes.

1 call to SitemapTaxonomyTestBase::addEntityreferenceField()
SitemapTaxonomyTestBase::createNodeWithTerms in src/Tests/SitemapTaxonomyTestBase.php
Create node and assign tags to it.

File

src/Tests/SitemapTaxonomyTestBase.php, line 141

Class

SitemapTaxonomyTestBase
Base class for some Sitemap test cases.

Namespace

Drupal\sitemap\Tests

Code

protected function addEntityreferenceField() {
  $this->fieldTagsName = 'field_' . $this->vocabulary
    ->id();
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];

  // Create the entity reference field for terms.
  $this
    ->createEntityReferenceField('node', 'article', $this->fieldTagsName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

  // Configure for autocomplete display.
  EntityFormDisplay::load('node.article.default')
    ->setComponent($this->fieldTagsName, [
    'type' => 'entity_reference_autocomplete_tags',
  ])
    ->save();
}