Chris@0: autoCreateBasicBlockType) { Chris@0: $this->createBlockContentType('basic', TRUE); Chris@0: } Chris@0: Chris@0: $this->adminUser = $this->drupalCreateUser($this->permissions); Chris@0: $this->drupalPlaceBlock('local_actions_block'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a custom block. Chris@0: * Chris@0: * @param bool|string $title Chris@0: * (optional) Title of block. When no value is given uses a random name. Chris@0: * Defaults to FALSE. Chris@0: * @param string $bundle Chris@0: * (optional) Bundle name. Defaults to 'basic'. Chris@0: * @param bool $save Chris@0: * (optional) Whether to save the block. Defaults to TRUE. Chris@0: * Chris@0: * @return \Drupal\block_content\Entity\BlockContent Chris@0: * Created custom block. Chris@0: */ Chris@0: protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) { Chris@0: $title = $title ?: $this->randomMachineName(); Chris@0: $block_content = BlockContent::create([ Chris@0: 'info' => $title, Chris@0: 'type' => $bundle, Chris@17: 'langcode' => 'en', Chris@0: ]); Chris@0: if ($block_content && $save === TRUE) { Chris@0: $block_content->save(); Chris@0: } Chris@0: return $block_content; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a custom block type (bundle). Chris@0: * Chris@0: * @param string $label Chris@0: * The block type label. Chris@0: * @param bool $create_body Chris@0: * Whether or not to create the body field Chris@0: * Chris@0: * @return \Drupal\block_content\Entity\BlockContentType Chris@0: * Created custom block type. Chris@0: */ Chris@0: protected function createBlockContentType($label, $create_body = FALSE) { Chris@0: $bundle = BlockContentType::create([ Chris@0: 'id' => $label, Chris@0: 'label' => $label, Chris@0: 'revision' => FALSE, Chris@0: ]); Chris@0: $bundle->save(); Chris@0: if ($create_body) { Chris@0: block_content_add_body_field($bundle->id()); Chris@0: } Chris@0: return $bundle; Chris@0: } Chris@0: Chris@0: }