function BlockContentTestBase::createBlockContentType
Same name in this branch
- 9 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
Same name in other branches
- 8.9.x core/modules/block_content/src/Tests/Views/BlockContentTestBase.php \Drupal\block_content\Tests\Views\BlockContentTestBase::createBlockContentType()
- 8.9.x core/modules/block_content/src/Tests/BlockContentTestBase.php \Drupal\block_content\Tests\BlockContentTestBase::createBlockContentType()
- 8.9.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
- 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
- 10 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
- 10 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
- 11.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
- 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
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.
File
-
core/
modules/ block_content/ tests/ src/ Functional/ BlockContentTestBase.php, line 104
Class
- BlockContentTestBase
- Sets up block content types.
Namespace
Drupal\Tests\block_content\FunctionalCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.