function CommentTestBase::createCommentType

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentTestBase.php \Drupal\Tests\comment\Functional\CommentTestBase::createCommentType()
  2. 8.9.x core/modules/comment/src/Tests/CommentTestBase.php \Drupal\comment\Tests\CommentTestBase::createCommentType()
  3. 8.9.x core/modules/comment/tests/src/Functional/CommentTestBase.php \Drupal\Tests\comment\Functional\CommentTestBase::createCommentType()
  4. 10 core/modules/comment/tests/src/Functional/CommentTestBase.php \Drupal\Tests\comment\Functional\CommentTestBase::createCommentType()

Creates a comment type (bundle).

Parameters

string $label: The comment type label.

Return value

\Drupal\comment\Entity\CommentType Created comment type.

2 calls to CommentTestBase::createCommentType()
CommentTypeTest::testCommentTypeCreation in core/modules/comment/tests/src/Functional/CommentTypeTest.php
Tests creating a comment type programmatically and via a form.
CommentTypeTest::testCommentTypeDeletion in core/modules/comment/tests/src/Functional/CommentTypeTest.php
Tests deleting a comment type that still has content.

File

core/modules/comment/tests/src/Functional/CommentTestBase.php, line 407

Class

CommentTestBase
Provides setup and helper methods for comment tests.

Namespace

Drupal\Tests\comment\Functional

Code

protected function createCommentType($label) {
    $bundle = CommentType::create([
        'id' => $label,
        'label' => $label,
        'description' => '',
        'target_entity_type_id' => 'node',
    ]);
    $bundle->save();
    return $bundle;
}

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