function StandardProfileTest::saveComment

Same name and namespace in other branches
  1. 8.9.x core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::saveComment()

Creates a comment entity.

Parameters

int $nid: Node id which will hold the comment.

int $uid: User id of the author of the comment. Can be NULL if $contact provided.

mixed $contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.

int $pid: Comment id of the parent comment in a thread.

Return value

\Drupal\comment\Entity\Comment The saved comment.

1 call to StandardProfileTest::saveComment()
StandardProfileTest::setUp in core/modules/rdf/tests/src/Functional/StandardProfileTest.php

File

core/modules/rdf/tests/src/Functional/StandardProfileTest.php, line 540

Class

StandardProfileTest
Tests the RDF mappings and RDFa markup on top of the standard profile.

Namespace

Drupal\Tests\rdf\Functional

Code

protected function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
    $values = [
        'entity_id' => $nid,
        'entity_type' => 'node',
        'field_name' => 'comment',
        'uid' => $uid,
        'pid' => $pid,
        'subject' => $this->randomMachineName(),
        'comment_body' => $this->randomMachineName(),
        'status' => 1,
    ];
    if ($contact) {
        $values += $contact;
    }
    $comment = Comment::create($values);
    $comment->save();
    return $comment;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.