function BlockContentTestBase::createBlockContentType

Same name in this branch
  1. 8.9.x core/modules/block_content/src/Tests/Views/BlockContentTestBase.php \Drupal\block_content\Tests\Views\BlockContentTestBase::createBlockContentType()
  2. 8.9.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  3. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  2. 9 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
  3. 10 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  4. 10 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
  5. 11.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  6. 11.x core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()

Creates a custom block type (bundle).

Parameters

string $label: The block type label.

bool $create_body: Whether or not to create the body field

Return value

\Drupal\block_content\Entity\BlockContentType Created custom block type.

1 call to BlockContentTestBase::createBlockContentType()
BlockContentTestBase::setUp in core/modules/block_content/src/Tests/BlockContentTestBase.php
Sets the test up.

File

core/modules/block_content/src/Tests/BlockContentTestBase.php, line 109

Class

BlockContentTestBase
Sets up block content types.

Namespace

Drupal\block_content\Tests

Code

protected function createBlockContentType($label, $create_body = FALSE) {
    $bundle = BlockContentType::create([
        'id' => $label,
        'label' => $label,
        'revision' => FALSE,
    ]);
    $bundle->save();
    if ($create_body) {
        block_content_add_body_field($bundle->id());
    }
    return $bundle;
}

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