block_content_add_body_field example


    else {
      $id = $values['id'];
    }
    $values += [
      'id' => $id,
      'label' => $id,
      'revision' => FALSE,
    ];
    $bundle = BlockContentType::create($values);
    $status = $bundle->save();
    block_content_add_body_field($bundle->id());

    $this->assertEquals(SAVED_NEW, $statusnew FormattableMarkup('Created block content type %bundle.', ['%bundle' => $bundle->id()]));
    return $bundle;
  }

}

  protected function createBlockContentType($id$label) {
    $bundle = BlockContentType::create([
      'id' => $id,
      'label' => $label,
      'revision' => 1,
    ]);
    $bundle->save();
    block_content_add_body_field($bundle->id());
  }

}
public function save(array $form, FormStateInterface $form_state) {
    $block_type = $this->entity;
    $status = $block_type->save();

    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    $logger = $this->logger('block_content');
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Block type %label has been updated.', ['%label' => $block_type->label()]));
      $logger->notice('Block type %label has been updated.', ['%label' => $block_type->label(), 'link' => $edit_link]);
    }
    else {
      block_content_add_body_field($block_type->id());
      $this->messenger()->addStatus($this->t('Block type %label has been added.', ['%label' => $block_type->label()]));
      $logger->notice('Block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
    }

    $form_state->setRedirectUrl($this->entity->toUrl('collection'));
  }

}
/** * {@inheritdoc} */
  protected function createEntity() {
    $block_content_type = BlockContentType::create([
      'id' => 'basic',
      'label' => 'basic',
      'revision' => FALSE,
    ]);
    $block_content_type->save();
    block_content_add_body_field($block_content_type->id());

    // Create a "Llama" content block.     $block_content = BlockContent::create([
      'info' => 'Llama',
      'type' => 'basic',
      'body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
    ]);
    $block_content->save();

    
/** * {@inheritdoc} */
  protected function createEntity() {
    if (!BlockContentType::load('basic')) {
      $block_content_type = BlockContentType::create([
        'id' => 'basic',
        'label' => 'basic',
        'revision' => TRUE,
      ]);
      $block_content_type->save();
      block_content_add_body_field($block_content_type->id());
    }

    // Create a "Llama" content block.     $block_content = BlockContent::create([
      'info' => 'Llama',
      'type' => 'basic',
      'body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
    ])
      
// Add a new bundle and add an editorial workflow.     $this->createContentType(['type' => 'bundle_with_section_field']);
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'bundle_with_section_field');

    // Add a new block content bundle to the editorial workflow.     BlockContentType::create([
      'id' => 'basic',
      'label' => 'Basic',
      'revision' => 1,
    ])->save();
    block_content_add_body_field('basic');

    $workflow->getTypePlugin()->addEntityTypeAndBundle('block_content', 'basic');
    $workflow->save();

    // Enable layout overrides.     LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->drupalLogin($this->drupalCreateUser([
      
/** * {@inheritdoc} */
  public function createEntity() {
    if (!BlockContentType::load('basic')) {
      $block_content_type = BlockContentType::create([
        'id' => 'basic',
        'label' => 'basic',
        'revision' => TRUE,
      ]);
      $block_content_type->save();
      block_content_add_body_field($block_content_type->id());
    }

    // Create a "Llama" content block.     $block_content = BlockContent::create([
      'info' => 'Llama',
      'type' => 'basic',
      'body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
    ])
      

  public function testAddHighlights() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $bundle = BlockContentType::create([
      'id' => 'basic',
      'label' => 'Basic block',
      'revision' => 1,
    ]);
    $bundle->save();
    block_content_add_body_field($bundle->id());

    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    $assert_session->elementsCount('css', '.layout-builder__add-section', 2);
    $assert_session->elementNotExists('css', '.is-layout-builder-highlighted');
    $page->clickLink('Add section');
    $this->assertNotEmpty($assert_session->waitForElement('css', '#drupal-off-canvas .item-list'));
    $assert_session->assertWaitOnAjaxRequest();

    // Highlight is present with AddSectionController.     $this->assertHighlightedElement('[data-layout-builder-highlight-id="section-0"]');
    $page->clickLink('Two column');
    
'value' => 'Node body',
        ],
      ],
    ]);

    $bundle = BlockContentType::create([
      'id' => 'basic',
      'label' => 'Basic block',
      'revision' => 1,
    ]);
    $bundle->save();
    block_content_add_body_field($bundle->id());

    BlockContent::create([
      'type' => 'basic',
      'info' => 'Block with link',
      'body' => [
        // Create a link that should be disabled in Layout Builder preview.         'value' => '<a id="link-that-should-be-disabled" href="/search/node">Take me away</a>',
        'format' => 'full_html',
      ],
    ])->save();

    
$bundle = BlockContentType::create($values);
    }
    else {
      $bundle = BlockContentType::create([
        'id' => $values,
        'label' => $values,
        'revision' => FALSE,
      ]);
    }
    $bundle->save();
    if ($create_body) {
      block_content_add_body_field($bundle->id());
    }
    return $bundle;
  }

}

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

    $this->drupalPlaceBlock('local_tasks_block');

    $bundle = BlockContentType::create([
      'id' => 'basic',
      'label' => 'Basic',
    ]);
    $bundle->save();
    block_content_add_body_field($bundle->id());
    BlockContent::create([
      'info' => 'My content block',
      'type' => 'basic',
      'body' => [
        [
          'value' => 'This is the block content',
          'format' => filter_default_format(),
        ],
      ],
    ])->save();

    
parent::setUp();

    // Create the "basic" block type.     $bundle = BlockContentType::create([
      'id' => 'basic',
      'label' => 'basic',
      'revision' => FALSE,
    ]);
    $bundle->save();

    // Add the body field to it.     block_content_add_body_field($bundle->id());
  }

  /** * Tests moderating content blocks. * * Blocks and any non-node-type-entities do not have a concept of * "published". As such, we must use the "default revision" to know what is * going to be "published", i.e. visible to the user. * * The one exception is a block that has never been "published". When a block * is first created, it becomes the "default revision". For each edit of the * block after that, Content Moderation checks the "default revision" to * see if it is set to a published moderation state. If it is not, the entity * being saved will become the "default revision". * * The test below is intended, in part, to make this behavior clear. * * @see \Drupal\content_moderation\EntityOperations::entityPresave * @see \Drupal\content_moderation\Tests\ModerationFormTest::testModerationForm */
Home | Imprint | This part of the site doesn't use cookies.