5 * Contains \Drupal\Console\Utils\Create\TermData.
8 namespace Drupal\Console\Utils\Create;
10 use Drupal\Core\Entity\EntityTypeManagerInterface;
11 use Drupal\Core\Entity\EntityFieldManagerInterface;
12 use Drupal\Core\Datetime\DateFormatterInterface;
13 use Drupal\Core\Language\LanguageInterface;
18 * @package Drupal\Console\Utils
20 class TermData extends Base
23 * Create and returns an array of new Terms.
25 * @param $vocabularies
31 public function create(
36 $siteVocabularies = $this->drupalApi->getVocabularies();
38 for ($i = 0; $i < $limit; $i++) {
40 $vocabulary = $vocabularies[array_rand($vocabularies)];
41 $term = $this->entityTypeManager->getStorage('taxonomy_term')->create(
44 'name' => $this->getRandom()->sentences(mt_rand(1, $nameWords), true),
46 'value' => $this->getRandom()->sentences(mt_rand(1, $nameWords)),
47 'format' => 'full_html',
49 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
53 $terms['success'][] = [
55 'vocabulary' => $siteVocabularies[$vocabulary],
56 'name' => $term->getName(),
58 } catch (\Exception $error) {
59 $terms['error'][] = $error->getMessage();