Chris@0: $this->randomMachineName(), Chris@0: 'description' => $this->randomMachineName(), Chris@17: 'vid' => mb_strtolower($this->randomMachineName()), Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'weight' => mt_rand(0, 10), Chris@0: ]); Chris@0: $vocabulary->save(); Chris@0: return $vocabulary; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new term with random properties in vocabulary $vid. Chris@0: * Chris@0: * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary Chris@0: * The vocabulary object. Chris@0: * @param array $values Chris@0: * (optional) An array of values to set, keyed by property name. If the Chris@0: * entity type has bundles, the bundle key has to be specified. Chris@0: * Chris@0: * @return \Drupal\taxonomy\Entity\Term Chris@0: * The new taxonomy term object. Chris@0: */ Chris@0: public function createTerm(Vocabulary $vocabulary, $values = []) { Chris@0: $filter_formats = filter_formats(); Chris@0: $format = array_pop($filter_formats); Chris@0: $term = Term::create($values + [ Chris@0: 'name' => $this->randomMachineName(), Chris@0: 'description' => [ Chris@0: 'value' => $this->randomMachineName(), Chris@0: // Use the first available text format. Chris@0: 'format' => $format->id(), Chris@0: ], Chris@0: 'vid' => $vocabulary->id(), Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: ]); Chris@0: $term->save(); Chris@0: return $term; Chris@0: } Chris@0: Chris@0: }