function BlockContentTestBase::createBlockContentType

Same name in this branch
  1. 11.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
Same name 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. 8.9.x core/modules/block_content/src/Tests/Views/BlockContentTestBase.php \Drupal\block_content\Tests\Views\BlockContentTestBase::createBlockContentType()
  4. 8.9.x core/modules/block_content/src/Tests/BlockContentTestBase.php \Drupal\block_content\Tests\BlockContentTestBase::createBlockContentType()
  5. 8.9.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  6. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContentType()
  7. 10 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContentType()
  8. 10 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::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.

6 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 109

Class

BlockContentTestBase
Sets up block content types.

Namespace

Drupal\Tests\block_content\Functional

Code

protected function createBlockContentType($values, $create_body = FALSE) {
    if (is_string($values)) {
        @trigger_error('Using the variable $values as string is deprecated in drupal:11.1.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) {
        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.