function BlockContentTranslationUITest::createBlockContent

Creates a custom block.

Parameters

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

bool|string $bundle: (optional) Bundle name. When no value is given, defaults to $this->bundle. Defaults to FALSE.

Return value

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

1 call to BlockContentTranslationUITest::createBlockContent()
BlockContentTranslationUITest::testDisabledBundle in core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php
Test that no metadata is stored for a disabled bundle.

File

core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php, line 98

Class

BlockContentTranslationUITest
Tests the block content translation UI.

Namespace

Drupal\Tests\block_content\Functional

Code

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

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