function BlockContentCreationTrait::createBlockContentType

Same name and namespace in other branches
  1. 11.x core/modules/block_content/tests/src/Traits/BlockContentCreationTrait.php \Drupal\Tests\block_content\Traits\BlockContentCreationTrait::createBlockContentType()

Creates a block type (bundle).

Parameters

array{id?: string, label?: string} $values: The values to create the block content type.

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

Return value

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

20 calls to BlockContentCreationTrait::createBlockContentType()
BlockContentCacheTagsTest::createEntity in core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
Creates the entity to be tested.
BlockContentResourceTestBase::createEntity in core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php
Creates the entity to be tested.
BlockContentTest::createEntity in core/modules/jsonapi/tests/src/Functional/BlockContentTest.php
Creates the entity to be tested.
BlockContentTestBase::createBlockContentType in core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php
Creates a block type (bundle).
BlockContentTestBase::setUp in core/modules/block_content/tests/src/Functional/BlockContentTestBase.php
Sets the test up.

... See full list

File

core/modules/block_content/tests/src/Traits/BlockContentCreationTrait.php, line 59

Class

BlockContentCreationTrait
Provides methods for creating block_content entities and types.

Namespace

Drupal\Tests\block_content\Traits

Code

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

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