Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

function EntityTestBase::createTaxonomyVocab

Creates taxonomy vocabulary with custom fields.

To create and attach fields it internally calls TMGMTEntityTestCaseUtility::attachFields(). You can than access these fields calling $this->field_names['node']['YOUR_BUNDLE_NAME'].

Parameters

string $vid: Vocabulary id.

string $human_name: Vocabulary human readable name.

bool|array $fields_translatable: Flag or definition array to determine which or all fields should be translatable.

Return value

stdClass Created vocabulary object.

File

src/Tests/EntityTestBase.php, line 88

Class

EntityTestBase
Utility test case class with helper methods to create entities and their fields with populated translatable content. Extend this class if you create tests in which you need Drupal entities and/or fields.

Namespace

Drupal\tmgmt\Tests

Code

function createTaxonomyVocab($machine_name, $human_name, $fields_translatable = TRUE) {
  $vocabulary = Vocabulary::create([
    'name' => $human_name,
    'vid' => $machine_name,
  ]);
  $vocabulary
    ->save();
  $this
    ->attachFields('taxonomy_term', $vocabulary
    ->id(), $fields_translatable);
  return $vocabulary;
}