enableLayoutBuilder example

/** * Installs the Layout Builder. * * Also configures and reloads the entity display. */
  protected function installLayoutBuilder() {
    $this->container->get('module_installer')->install(['layout_builder']);
    $this->refreshServices();

    $this->display = $this->reloadEntity($this->display);
    $this->display->enableLayoutBuilder()->save();
    $this->entity = $this->reloadEntity($this->entity);
  }

  /** * Enables overrides for the display and reloads the entity. */
  protected function enableOverrides() {
    $this->display->setOverridable()->save();
    $this->entity = $this->reloadEntity($this->entity);
  }

  

  protected static $modules = ['layout_builder'];

  /** * {@inheritdoc} */
  protected function createEntity() {
    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
    $entity = parent::createEntity();
    $entity
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections'));
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    
$user = $this->drupalCreateUser([
      'configure any layout',
      'access contextual links',
      'administer nodes',
      'bypass node access',
      'administer views',
    ]);
    $user->save();
    $this->drupalLogin($user);
    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->createNode([
      'type' => 'bundle_with_section_field',
      'body' => [
        [
          'value' => 'The node body',
        ],
      ],
    ]);
  }

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->createNode([
      'type' => 'bundle_with_section_field',
    ]);
    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
    ]));
  }

  
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
    ]));
    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->createNode(['type' => 'bundle_with_section_field']);
  }

  /** * Tests block filter. */
  public function testBlockFilter() {
    $assert_session = $this->assertSession();
    $session = $this->getSession();
    
protected function setUp(): void {
    parent::setUp();
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // @todo The Layout Builder UI relies on local tasks; fix in     // https://www.drupal.org/project/drupal/issues/2917777.     $this->drupalPlaceBlock('local_tasks_block');

    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->createNode([
      'type' => 'bundle_with_section_field',
    ]);

    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
      'access contextual links',
    ]));

    

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function createEntity() {
    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
    $entity = parent::createEntity();
    $entity
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections'));
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $document = parent::getExpectedDocument();
    
'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([
      'configure any layout',
      'edit any bundle_with_section_field content',
      'view bundle_with_section_field revisions',
      'revert bundle_with_section_field revisions',
      'view own unpublished content',
      'view latest version',
      'use editorial transition create_new_draft',
      
/** * Set up the View Display. */
  protected function setUpViewDisplay() {
    EntityViewDisplay::create([
      'targetEntityType' => $this->entityTypeId,
      'bundle' => $this->bundle,
      'mode' => 'default',
      'status' => TRUE,
    ])
      ->setComponent($this->fieldName, ['type' => 'string'])
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
  }

  /** * Adds an entity translation. */
  protected function addEntityTranslation() {
    $user = $this->loggedInUser;
    $this->drupalLogin($this->translator);
    $add_translation_url = Url::fromRoute("entity.$this->entityTypeId.content_translation_add", [
      
'name' => 'bundle_referenced',
    ]);

    $this->createEntityReferenceField('node', 'bundle_with_reference_field', 'field_reference', 'Reference field', 'node', 'default', [
      'target_bundles' => ['bundle_referenced'],
    ]);

    // Enable layout builder to the content type with the reference field, and     // add the reference field to the layout builder display.     $this->container->get('entity_display.repository')
      ->getViewDisplay('node', 'bundle_with_reference_field', 'full')
      ->enableLayoutBuilder()
      ->setComponent('field_reference', ['type' => 'entity_reference_label'])
      ->save();
  }

  /** * Tests cache tags on field block for entity reference field. */
  public function testEntityReferenceFieldBlockCaching() {
    $assert_session = $this->assertSession();

    // Create two nodes, one of the referenced content type and one of the
/** * {@inheritdoc} */
  public function isLayoutBuilderEnabled() {
    return $this->getDisplay()->isLayoutBuilderEnabled();
  }

  /** * {@inheritdoc} */
  public function enableLayoutBuilder() {
    $this->getDisplay()->enableLayoutBuilder();
    return $this;
  }

  /** * {@inheritdoc} */
  public function disableLayoutBuilder() {
    $this->getDisplay()->disableLayoutBuilder();
    return $this;
  }

  

    $this->createFileField('field_file', 'block_content', 'basic', $field_settings);
    $this->fileSystem = $this->container->get('file_system');
  }

  /** * Tests access to private files added to inline blocks in the layout builder. */
  public function testPrivateFiles() {
    $assert_session = $this->assertSession();
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    // Log in as user you can only configure layouts and access content.     $this->drupalLogin($this->drupalCreateUser([
      'access contextual links',
      'configure any layout',
      'access content',
      'create and edit custom blocks',
    ]));
    $this->drupalGet('node/1/layout');
    

  public function testAccess($expected$operation$is_enabled, array $section_data) {
    $display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
      'status' => TRUE,
    ]);
    if ($is_enabled) {
      $display->enableLayoutBuilder();
    }
    $display
      ->setThirdPartySetting('layout_builder', 'sections', $section_data)
      ->save();

    $this->plugin->setContext('display', EntityContext::fromEntity($display));
    $result = $this->plugin->access($operation);
    $this->assertSame($expected$result);
  }

  /** * Provides test data for ::testAccess(). */
protected $nodeStorage;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $assert_session = $this->assertSession();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
      'bypass node access',
      'create bundle_with_section_field content',
      'edit any bundle_with_section_field content',
    ]));
    $page = $this->getSession()->getPage();

    
/** * {@inheritdoc} */
  protected function getSectionList(array $section_data) {
    $this->installEntitySchema('entity_test_base_field_display');
    LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test_base_field_display',
      'bundle' => 'entity_test_base_field_display',
      'mode' => 'default',
      'status' => TRUE,
    ])
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    array_map(function D$row) {
      return ['section' => $row];
    }$section_data);
    $entity = EntityTestBaseFieldDisplay::create([
      'name' => 'The test entity',
      OverridesSectionStorage::FIELD_NAME => $section_data,
    ]);
    $entity->save();
    
Home | Imprint | This part of the site doesn't use cookies.