You are here

protected function BlockContentTestBase::createBlockContentType in Drupal 9

Same name in this branch
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
  2. 9 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
Same name and namespace in other branches
  1. 8 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
  2. 10 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()

Creates a custom block type (bundle).

Parameters

array|string $values: The value to create the block content type. If $values is an array it should be like: ['id' => 'foo', 'label' => 'Foo']. If $values is a string, it will be considered that it represents the label.

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

Return value

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

7 calls to BlockContentTestBase::createBlockContentType()
BlockContentTestBase::setUp in core/modules/block_content/tests/src/Functional/BlockContentTestBase.php
Sets the test up.
BlockContentTypeTest::testBlockContentAddPageOrder in core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php
Tests the order of the block content types on the add page.
BlockContentTypeTest::testBlockContentTypeCreation in core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php
Tests creating a block type programmatically and via a form.
BlockContentTypeTest::testBlockContentTypeDeletion in core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php
Tests deleting a block type that still has content.
BlockContentTypeTest::testBlockContentTypeEditing in core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php
Tests editing a block type using the UI.

... See full list

File

core/modules/block_content/tests/src/Functional/BlockContentTestBase.php, line 104

Class

BlockContentTestBase
Sets up block content types.

Namespace

Drupal\Tests\block_content\Functional

Code

protected function createBlockContentType($values, $create_body = FALSE) {
  if (is_array($values)) {
    if (!isset($values['id'])) {
      do {
        $id = strtolower($this
          ->randomMachineName(8));
      } while (BlockContentType::load($id));
    }
    else {
      $id = $values['id'];
    }
    $values += [
      'id' => $id,
      'label' => $id,
      'revision' => FALSE,
    ];
    $bundle = BlockContentType::create($values);
  }
  else {
    $bundle = BlockContentType::create([
      'id' => $values,
      'label' => $values,
      'revision' => FALSE,
    ]);
  }
  $bundle
    ->save();
  if ($create_body) {
    block_content_add_body_field($bundle
      ->id());
  }
  return $bundle;
}