createBlockContentType example

'block',
    'block_content',
    'block_content_test_views',
  ];

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['block_content_test_views']): void {
    parent::setUp($import_test_views$modules);
    // Ensure the basic bundle exists. This is provided by the standard profile.     $this->createBlockContentType(['id' => 'basic']);

    $this->adminUser = $this->drupalCreateUser($this->permissions);
  }

  /** * Creates a content block. * * @param array $values * (optional) The values for the block_content entity. * * @return \Drupal\block_content\Entity\BlockContent * Created content block. */
public static $testViews = ['test_block_content_view'];

  /** * Tests basic block_content view with a block_content_type argument. */
  public function testBlockContentViewTypeArgument() {
    // Create two content types with three block_contents each.     $types = [];
    $all_ids = [];
    $block_contents = [];
    for ($i = 0; $i < 2; $i++) {
      $type = $this->createBlockContentType();
      $types[] = $type;

      for ($j = 0; $j < 5; $j++) {
        // Ensure the right order of the block_contents.         $block_content = $this->createBlockContent(['type' => $type->id()]);
        $block_contents[$type->id()][$block_content->id()] = $block_content;
        $all_ids[] = $block_content->id();
      }
    }

    $this->drupalGet('test-block_content-view');
    

  protected $autoCreateBasicBlockType = TRUE;

  /** * Sets the test up. */
  protected function setUp(): void {
    parent::setUp();
    if ($this->autoCreateBasicBlockType) {
      $this->createBlockContentType('basic', TRUE);
    }

    $this->adminUser = $this->drupalCreateUser($this->permissions);
    $this->drupalPlaceBlock('local_actions_block');
  }

  /** * Creates a content block. * * @param bool|string $title * (optional) Title of block. When no value is given uses a random name. * Defaults to FALSE. * @param string $bundle * (optional) Bundle name. Defaults to 'basic'. * @param bool $save * (optional) Whether to save the block. Defaults to TRUE. * * @return \Drupal\block_content\Entity\BlockContent * Created content block. */

    ]);
    $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The node2 title',
      'body' => [
        [
          'value' => 'The node2 body',
        ],
      ],
    ]);
    $this->createBlockContentType('basic', 'Basic block');

    $this->blockStorage = $this->container->get('entity_type.manager')->getStorage('block_content');
  }

  /** * Saves a layout and asserts the message is correct. */
  protected function assertSaveLayout() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm(['layout[enabled]' => TRUE, 'layout[allow_custom]' => TRUE], 'Save');

    $layout_default_path = 'admin/structure/types/manage/bundle_with_section_field/display/default/layout';
    $this->drupalGet($layout_default_path);
    // Add a basic block with the body field set.     $page->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();
    // Confirm that with no block content types the link does not appear.     $assert_session->linkNotExists('Create content block');

    $this->createBlockContentType('basic', 'Basic block');

    $this->drupalGet($layout_default_path);
    // Add a basic block with the body field set.     $page->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();
    // Confirm with only 1 type the "Create content block" link goes directly t     // block add form.     $assert_session->linkNotExists('Basic block');
    $this->clickLink('Create content block');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->fieldExists('Title');

    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->drupalCreateUser(['administer views']));
    $this->createBlockContentType('Basic block');
  }

  /** * Tests creating a 'block_content' entity view. */
  public function testViewAddBlockContent() {
    $view = [];
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['description'] = $this->randomMachineName(16);
    $view['page[create]'] = FALSE;
    

  protected function setUp(): void {
    parent::setUp();

    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Tests the order of the block content types on the add page. */
  public function testBlockContentAddPageOrder() {
    $this->createBlockContentType(['id' => 'bundle_1', 'label' => 'Bundle 1']);
    $this->createBlockContentType(['id' => 'bundle_2', 'label' => 'Aaa Bundle 2']);
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('block/add');
    $this->assertSession()->pageTextMatches('/Aaa Bundle 2(.*)Bundle 1/');
  }

  /** * Tests creating a block type programmatically and via a form. */
  public function testBlockContentTypeCreation() {
    // Log in a test user.
Home | Imprint | This part of the site doesn't use cookies.