function BlockContentTestBase::createBlockContent

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::createBlockContent()
Same name in other branches
  1. 9 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContent()
  2. 9 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContent()
  3. 8.9.x core/modules/block_content/src/Tests/Views/BlockContentTestBase.php \Drupal\block_content\Tests\Views\BlockContentTestBase::createBlockContent()
  4. 8.9.x core/modules/block_content/src/Tests/BlockContentTestBase.php \Drupal\block_content\Tests\BlockContentTestBase::createBlockContent()
  5. 8.9.x core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContent()
  6. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContent()
  7. 10 core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase::createBlockContent()
  8. 10 core/modules/block_content/tests/src/Functional/BlockContentTestBase.php \Drupal\Tests\block_content\Functional\BlockContentTestBase::createBlockContent()

Creates a content block.

Parameters

bool|string $title: (optional) Title of block. When no value is given uses a random name. Defaults to FALSE.

string $bundle: (optional) Bundle name. Defaults to 'basic'.

bool $save: (optional) Whether to save the block. Defaults to TRUE.

Return value

\Drupal\block_content\Entity\BlockContent Created content block.

11 calls to BlockContentTestBase::createBlockContent()
BlockContentContextualLinksTest::testBlockContentContextualLinks in core/modules/block_content/tests/src/Functional/BlockContentContextualLinksTest.php
Tests contextual links.
BlockContentCreationTest::testConfigDependencies in core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php
Tests placed content blocks create a dependency in the block placement.
BlockContentCreationTest::testFailedBlockCreation in core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php
Verifies that a transaction rolls back the failed creation.
BlockContentListTest::testListing in core/modules/block_content/tests/src/Functional/BlockContentListTest.php
Tests the content block listing page with different permissions.
BlockContentListViewsTest::testListing in core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
Tests the content block listing page.

... See full list

File

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

Class

BlockContentTestBase
Sets up block content types.

Namespace

Drupal\Tests\block_content\Functional

Code

protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
    $title = $title ?: $this->randomMachineName();
    $block_content = BlockContent::create([
        'info' => $title,
        'type' => $bundle,
        'langcode' => 'en',
    ]);
    if ($block_content && $save === TRUE) {
        $block_content->save();
    }
    return $block_content;
}

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