5 * Contains \Drupal\Console\Utils\Create\VocabularyData.
8 namespace Drupal\Console\Utils\Create;
10 use Drupal\Component\Utility\Unicode;
11 use Drupal\Core\Entity\EntityTypeManagerInterface;
12 use Drupal\Core\Entity\EntityFieldManagerInterface;
13 use Drupal\Core\Datetime\DateFormatterInterface;
14 use Drupal\Core\Language\LanguageInterface;
19 * @package Drupal\Console\Utils
21 class VocabularyData extends Base
24 * Vocabularies constructor.
26 * @param EntityTypeManagerInterface $entityManager
27 * @param EntityFieldManagerInterface $entityFieldManager
28 * @param DateFormatterInterface $dateFormatter
30 public function __construct(
31 EntityTypeManagerInterface $entityManager,
32 EntityFieldManagerInterface $entityFieldManager,
33 DateFormatterInterface $dateFormatter
43 * Create and returns an array of new Vocabularies.
50 public function create(
55 for ($i=0; $i<$limit; $i++) {
57 // Create a vocabulary.
58 $vocabulary = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->create(
60 'name' => $this->getRandom()->sentences(mt_rand(1, $nameWords), true),
61 'description' => $this->getRandom()->sentences(),
62 'vid' => Unicode::strtolower($this->getRandom()->name()),
63 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
64 'weight' => mt_rand(0, 10),
70 $vocabularies['success'][] = [
71 'vid' => $vocabulary->id(),
72 'vocabulary' => $vocabulary->get('name'),
74 } catch (\Exception $error) {
75 $vocabularies['error'][] = [
76 'vid' => $vocabulary->id(),
77 'name' => $vocabulary->get('name'),
78 'error' => $error->getMessage()