function BlockContentCreationTrait::createBlockContentType
Creates a block type (bundle).
Parameters
array|string $values: (deprecated) The variable $values as string is deprecated. Provide as an array as parameter. 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 block type.
19 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.
File
-
core/
modules/ block_content/ tests/ src/ Traits/ BlockContentCreationTrait.php, line 63
Class
- BlockContentCreationTrait
- Provides methods for creating block_content entities and types.
Namespace
Drupal\Tests\block_content\TraitsCode
protected function createBlockContentType(array|string $values, bool $create_body = FALSE) : BlockContentType {
if (is_string($values)) {
@trigger_error('Using the variable $values as string is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Provide an array as parameter. See https://www.drupal.org/node/3473739', E_USER_DEPRECATED);
}
if (is_array($values)) {
if (!isset($values['id'])) {
do {
$id = $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) {
$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.