You are here

protected function SiteMapTestBase::createTaxonomyTermReferenceField in Site map 8

Create taxonomy term reference field for testing categories.

Parameters

object $vocabulary: Taxonomy vocabulary.

Return value

string Created field name.

3 calls to SiteMapTestBase::createTaxonomyTermReferenceField()
SiteMapCategoriesTest::setUp in src/Tests/SiteMapCategoriesTest.php
Sets up a Drupal site for running functional and integration tests.
SiteMapContentTest::testCategories in src/Tests/SiteMapContentTest.php
Tests categories.
SiteMapRssTest::setUp in src/Tests/SiteMapRssTest.php
Sets up a Drupal site for running functional and integration tests.

File

src/Tests/SiteMapTestBase.php, line 132

Class

SiteMapTestBase
Base class for Site Map test cases.

Namespace

Drupal\site_map\Tests

Code

protected function createTaxonomyTermReferenceField($vocabulary) {
  $field_tags_name = Unicode::strtolower($this
    ->randomMachineName());
  $field_storage = entity_create('field_storage_config', array(
    'field_name' => $field_tags_name,
    'entity_type' => 'node',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary
            ->id(),
          'parent' => '0',
        ),
      ),
    ),
  ));
  $field_storage
    ->save();
  entity_create('field_config', array(
    'field_storage' => $field_storage,
    'bundle' => 'article',
  ))
    ->save();
  entity_get_form_display('node', 'article', 'default')
    ->setComponent($field_tags_name, array(
    'type' => 'taxonomy_autocomplete',
  ))
    ->save();
  entity_get_display('node', 'article', 'full')
    ->setComponent($field_tags_name, array(
    'type' => 'taxonomy_term_reference_link',
  ))
    ->save();
  return $field_tags_name;
}