function BlockContentTestBase::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.

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 custom block.

File

core/modules/block_content/src/Tests/BlockContentTestBase.php, line 85

Class

BlockContentTestBase
Sets up block content types.

Namespace

Drupal\block_content\Tests

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.