以编程方式创建评论

create comments programmatically


use Drupal\comment\Entity\Comment;
  $comment = Comment::create(array(
    'entity_type' => 'node',            
    'entity_id'   => 3,            
    'field_name'  => 'comment',       
    'uid' => 24,                       
    'comment_type' => 'comment',     
    'subject' => $subject,  
    'comment_body' => $body,       
    'status' => 1,                 
     ));
  $comment->save();
$commentid = $comment->id();
 echo $commentid;
$node=NULL;//