5 * Contains \Drupal\Console\Utils\Create\NodeData.
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 NodeData extends Base
23 * @param $contentTypes
30 public function create(
35 $language = LanguageInterface::LANGCODE_NOT_SPECIFIED
38 $bundles = $this->drupalApi->getBundles();
39 for ($i = 0; $i < $limit; $i++) {
41 $contentType = $contentTypes[array_rand($contentTypes)];
42 $node = $this->entityTypeManager->getStorage('node')->create(
45 'type' => $contentType,
46 'created' => REQUEST_TIME - mt_rand(0, $timeRange),
47 'uid' => $this->getUserID(),
48 'title' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
49 'revision' => mt_rand(0, 1),
51 'promote' => mt_rand(0, 1),
52 'langcode' => $language
56 $this->generateFieldSampleData($node);
58 $nodes['success'][] = [
60 'node_type' => $bundles[$contentType],
61 'title' => $node->getTitle(),
62 'created' => $this->dateFormatter->format(
63 $node->getCreatedTime(),
68 } catch (\Exception $error) {
69 $nodes['error'][] = $error->getMessage();