5 * Contains \Drupal\Console\Utils\Create\CommentData.
8 namespace Drupal\Console\Utils\Create;
10 use Drupal\Core\Entity\EntityTypeManagerInterface;
11 use Drupal\Core\Entity\EntityFieldManagerInterface;
12 use Drupal\Core\Datetime\DateFormatterInterface;
17 * @package Drupal\Console\Utils\Create
19 class CommentData extends Base
22 * Comments constructor.
24 * @param EntityTypeManagerInterface $entityTypeManager
25 * @param EntityFieldManagerInterface $entityFieldManager
26 * @param DateFormatterInterface $dateFormatter
28 public function __construct(
29 EntityTypeManagerInterface $entityTypeManager,
30 EntityFieldManagerInterface $entityFieldManager,
31 DateFormatterInterface $dateFormatter
48 public function create(
56 for ($i=0; $i<$limit; $i++) {
57 $comment = $this->entityTypeManager->getStorage('comment')->create(
60 'entity_type' => 'node',
61 'field_name' => 'comment',
62 'created' => REQUEST_TIME - mt_rand(0, $timeRange),
63 'uid' => $this->getUserID(),
65 'subject' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
67 'comment_body' => ['und' => ['random body']],
71 $this->generateFieldSampleData($comment);
75 $comments['success'][] = [
77 'cid' => $comment->id(),
78 'title' => $comment->getSubject(),
79 'created' => $this->dateFormatter->format(
80 $comment->getCreatedTime(),
85 } catch (\Exception $error) {
86 $comments['error'][] = [
87 'title' => $comment->getTitle(),
88 'error' => $error->getMessage()