protected function VocabularyDevelGenerate::generateVocabularies in Devel 8.3
Same name and namespace in other branches
- 8 devel_generate/src/Plugin/DevelGenerate/VocabularyDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\VocabularyDevelGenerate::generateVocabularies()
- 8.2 devel_generate/src/Plugin/DevelGenerate/VocabularyDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\VocabularyDevelGenerate::generateVocabularies()
- 4.x devel_generate/src/Plugin/DevelGenerate/VocabularyDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\VocabularyDevelGenerate::generateVocabularies()
Generates vocabularies.
Parameters
int $records: Number of vocabularies to create.
int $maxlength: (optional) Maximum length for vocabulary name.
Return value
array Array containing the generated vocabularies id.
1 call to VocabularyDevelGenerate::generateVocabularies()
- VocabularyDevelGenerate::generateElements in devel_generate/
src/ Plugin/ DevelGenerate/ VocabularyDevelGenerate.php - Business logic relating with each DevelGenerate plugin.
File
- devel_generate/
src/ Plugin/ DevelGenerate/ VocabularyDevelGenerate.php, line 127
Class
- VocabularyDevelGenerate
- Provides a VocabularyDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
protected function generateVocabularies($records, $maxlength = 12) {
$vocabularies = [];
// Insert new data:
for ($i = 1; $i <= $records; $i++) {
$name = $this
->getRandom()
->word(mt_rand(2, $maxlength));
$vocabulary = $this->vocabularyStorage
->create([
'name' => $name,
'vid' => mb_strtolower($name),
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
'description' => "Description of {$name}",
'hierarchy' => 1,
'weight' => mt_rand(0, 10),
'multiple' => 1,
'required' => 0,
'relations' => 1,
]);
// Populate all fields with sample values.
$this
->populateFields($vocabulary);
$vocabulary
->save();
$vocabularies[] = $vocabulary
->id();
unset($vocabulary);
}
return $vocabularies;
}