function EntityTestBase::createTaxonomyVocab in Translation Management Tool 8
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\TestsCode
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;
}