X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FUtils%2FCreate%2FCommentData.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FUtils%2FCreate%2FCommentData.php;h=1a6b9cca828266152ff708b017fa5fdfaa00a2a2;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Utils/Create/CommentData.php b/vendor/drupal/console/src/Utils/Create/CommentData.php new file mode 100644 index 000000000..1a6b9cca8 --- /dev/null +++ b/vendor/drupal/console/src/Utils/Create/CommentData.php @@ -0,0 +1,95 @@ +entityTypeManager->getStorage('comment')->create( + [ + 'entity_id' => $nid, + 'entity_type' => 'node', + 'field_name' => 'comment', + 'created' => REQUEST_TIME - mt_rand(0, $timeRange), + 'uid' => $this->getUserID(), + 'status' => true, + 'subject' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true), + 'language' => 'und', + 'comment_body' => ['und' => ['random body']], + ] + ); + + $this->generateFieldSampleData($comment); + + try { + $comment->save(); + $comments['success'][] = [ + 'nid' => $nid, + 'cid' => $comment->id(), + 'title' => $comment->getSubject(), + 'created' => $this->dateFormatter->format( + $comment->getCreatedTime(), + 'custom', + 'Y-m-d h:i:s' + ) + ]; + } catch (\Exception $error) { + $comments['error'][] = [ + 'title' => $comment->getTitle(), + 'error' => $error->getMessage() + ]; + } + } + + return $comments; + } +}